http请求与后端参数接收
1.get请求
get请求中参数是放在uri里面,
get请求,无论是url上带参数还是单独放置参数(ajax get请求会把data拼接到url上),后端用@RequestParam接收参数即可,或者在后端函数中写上相应的参数不需增加注解。
2.post请求
post请求中参数是放在body里面的
contentType: 告诉服务器,我要发什么类型的数据
dataType:告诉服务器,我要想什么类型的数据,如果没有指定,那么会自动推断是返回 XML,还是JSON,还是script,还是String
contentType | 服务器接收 | 说明 |
"application/json" | @RequestBody | @RequestBody Map<String,String> params @RequestBody String params
|
application/x-www-form-urlencoded | request.getParameter(),或者使用@RequestParam | contentType都是默认的值:application/x-www-form-urlencoded,这种格式的特点就是,name/value 成为一组,每组之间用 & 联接,而 name与value 则是使用 = 连接。如: wwwh.baidu.com/q?key=fdsa&lang=zh |
multipart/form-data
| MultipartFile file | 在SpringBoot中可以通过MulTipartFile数组接收多个文件,一些其它的参数也可以直接写到函数的参数中 |
text/xml |
| 这种直接传的xml格式 |
|
| @PathVariable获取 restful 风格参数url/param |
|
|
|