@requestbody与415状态码

 1.
@requestbody与415状态码,需要配置相关bean, spring4.3.*以上需要Jackson包2.7.5及以上的jar包
还有可能在jsp页面中function的命名使用了关键字
maven项目中可以在pom.xml中添加下列代码获取依赖包
<dependency>
             <groupId>com.fasterxml.jackson.core</groupId>
             <artifactId>jackson-core</artifactId>
             <version>2.7.5</version>
       </dependency>
       <dependency>
             <groupId>com.fasterxml.jackson.core</groupId>
             <artifactId>jackson-annotations</artifactId>
             <version>2.7.5</version>
       </dependency>
       <dependency>
             <groupId>com.fasterxml.jackson.core</groupId>
             <artifactId>jackson-databind</artifactId>
             <version>2.7.5</version>
       </dependency>

       <dependency>
             <groupId>org.codehaus.jackson</groupId>
             <artifactId>jackson-mapper-asl</artifactId>
             <version>1.9.4</version>
       </dependency>
       
       <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-core-asl</artifactId>
            <version>1.9.4</version>
       </dependency>

2.

@requestbody与415状态码,如果在前端jsp的JavaScript代码中使用关键字也会出现当前错误

function submit() {}

上述function使用了submit作为函数名,则也会出现415错误

3

请求路劲没有出错并且不存在跨域,出现415错误

解决方法:在ajax请求中加上contentType: 'application/json',
$.ajax({<br>   type: "POST",
   contentType: 'application/json;charset=UTF-8',
   url: getLoginVerifyCodeUrl,
   dataType: "json",
   data: loginPostData,
   async: false
});

4

加上之后报400错,首先确定后端需要的数据格式、数据字段等等与你发送的数据格式、数据字段等是否相同,

如果发送的是json格式的,在判定上述都没有问题时,将发送的数据使用loginPostData = JSON.stringify(loginPostData);转换之后再试。

猜你喜欢

转载自blog.csdn.net/qq_34608620/article/details/80635090