文章目录
1.使用@RequestBody 接收前端传到后端的json数据时,页面出现415
解决办法1
在pom.xml中加入
<!-- 解决json转化的问题=======-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.12.5</version>
</dependency>
解决办法2
axios坐标
<!-- Ajax框架 Axios入门 到的js--> <dependency> <groupId>org.webjars.npm</groupId> <artifactId>axios</artifactId> <version>0.25.0</version> </dependency>
在从前端用Ajax(这里我用的axios)传数据时设置 ‘Content-Type’:‘application/json’
axios({ method:"post", url:"/brand/condition_select?begin="+_this.currentPage+"&size="+_this.pageSize, data:_this.formInline, header:{ 'Content-Type':'application/json' //如果写成contentType会报错 } }).then(function (resp) { _this.tableData= resp.data.rows; _this.totalCount=resp.data.totalCount })
2.获取Cookie时,使用F12,查看Cookie储存时的路径,只有路径一致才可以获取Cookie
3.如果web层方法的返回值为Spring,页面显示乱码
解决方法
@RequestMapping(value = "/selectBrandId",produces ="text/html;charset=UTF-8")
4.如果Web层的方法返回值为Bean或者Bean集合,并且使用@ResponseBody作为标记
不需要加
@RequestMapping(value = "/selectBrandId",produces ="text/html;charset=UTF-8")
只需要写路径
@RequestMapping(value = "/selectBrandId")
给那些看完的朋友,奖励一个 赤赤博客-后端+前端,觉得不错的话可以推荐给身边的朋友哟!