传统拼接方式
地址① http://localhost:8989/SSSP/emps?pageNo=2
restful风格:
地址② http://localhost:8989/SSSP/emp/7
如果想获取地址①中的 pageNo的值 ‘2’ ,则使用 @RequestParam ,
如果想获取地址②中的 emp/7 中的 ‘7 ’ 则使用 @PathVariable
@GetMapping("/param")
//get请求简单接受,请求中没有str不hi报错,str为null
public String getMethod( String str){
System.out.println("str:"+str);
return str;
}
@GetMapping("/param")
//如果加了@RequestParam,请求中必须带str 参数名,不带会报错
public String getMethod(@RequestParam String str){
System.out.println("str:"+str);
return str;
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public Product get(@PathVariable(value = "id", required = true) Long id)
@RequestMapping(value="/emp/{id}",method=RequestMethod.GET)
public String edit(@PathVariable("id")Integer id,Map
@RequestParam 用来接收 地址栏 json格式数据(字符串、数组)
@PathVariable:占位符,用于restful风格
post请求
@PostMapping("/post3")
public String postMethod3( @RequestBody String str){
System.out.println("str:"+str);
return str;
}
====输出====
str:{
"str":"123"
}
============
@RequestMapping(value = "/add", method = RequestMethod.POST)
public AjaxResult save(@RequestBody Product product) {}
@RequestBody: 转成json K-V形式接受参数,适合接收对象
content-type
Content-Type(MediaType),即是Internet Media Type,互联网媒体类型;也叫做MIME类型,在Http协议消息头中,使用Content-Type来表示具体请求中的媒体类型信息.参考
response.Header里常见Content-Type一般有以下四种:
- application/x-www-form-urlencoded :标准格式
- multipart/form-data:post表单中有type=file控件时content-type会使用此编码方式.
- application/json :最常用
- text/xml
https://my.oschina.net/u/3086656/blog/5128991
https://www.cnblogs.com/huanghuizhou/p/9887757.html



