1、请求方式默认规则
- 获取资源:method = RequestMethod.GET
- 修改资源:method = RequestMethod.PUT
- 新增资源:method = RequestMethod.POST
- 删除资源:method = RequestMethod.DELETE
2、参数传递方式
1)基本类型参数
参数名以大括号包裹,拼接到url后,控制层方法内以@PathVariable接收该参数
@RequestMapping(method = RequestMethod.GET,value = "/{name}") public UserInfo getUserInfoWithRoleByName(@PathVariable("name")String name) { return userInfoService.getUserInfoWithRoleByName(name); }
2)自定义对象参数
api接口定义为post请求方式,控制层方法内以@RequestBody接收该参数
@RequestMapping(method = RequestMethod.POST ,consumes = "application/json;charset=UTF-8") public Integer addUserInfo(@RequestBody UserInfo userInfo){ return userInfoService.addUserInfo(userInfo); }