前后端数据传输方式总结

1.GET方法传输数据

直接在后面添加参数即可
例如
?count=1&datajs=rcss&programId=123
后台接收数据直接使用参数接收即可,不需要附带注解

2.POST使用Form表单方法

使用Form表单传输数据
Content-Type:multipart/form-data; boundary=----WebKitFormBoundary9tB9D5qPF5BBA58h
数据格式:
前后端数据传输方式总结
后台可直接接收数据,不需要注解,int型数据接收时需要使用Integer接收

3.POST 使用json传数据,传List<对象>数据

只能用一个参数接收数据,即使用一个List<对象>,在接收数据时,必须使用@ResquestBody
前端传数据方式
Content-Type:application/json
[
{“exhibitId”:13,“state”:1,“comments”:“tongguo”},
{“exhibitId”:14,“state”:1,“comments”:“tongguo”},
{“exhibitId”:15,“state”:1,“comments”:“tongguo”}
]
后台接收数据方式:
@RequestBody List list

4.总结

使用json传数据时,后台接收数据必须需要使用到@ResquestBody,不然会传空,而且一次只能传一个数据,不能够多传;或者说在后台只能由一个参数来接收数据;如果接收参数时使用了对象或者List,则会自动转换格式

正确的格式:
@RequestMapping(value="/exhibit/test4json4", method = RequestMethod.POST)
public void test4(@RequestBody List in1){
int a =1;
}
错误的格式:
@RequestMapping(value="/exhibit/test4json4", method = RequestMethod.POST)
public void test4(@RequestBody Integer in1,Integer ttt){
int a =1;
}