@RequestMapper六个属性及七个方法参数注解
此乃个人笔记,适合有一定了解的人看,若看不懂,可点击参考链接,里面有每个属性与注解的具体代码示例
@RestController
@Requestbody和@Controller的结合体
@ReuqestMapper
一句话概括:六个参数 value(请求路径) method(请求类型) produces(返回数据类型) consumes(请求数据类型) params(请求参数) heads(请求头)
- value:请求路径;
- mothod:请求类型 get post put delete;
- consumes:指定处理请求的提交内容类型(content-type)eg:application/json text/html;
- produces:指定返回数据类型,request请求头(accept)类型中包含该指定类型,才返回;
- params:指定request中必须包含指定参数值,才让方法处理;
- headers:指定request包含指定header值,才处理;
- 参考链接:https://blog.csdn.net/longcccvv/article/details/54289022
方法参数
常用:@RequestBody @RequestParam @RequestHeader @PathVariable
- @RequestBody:处理Content-Type 非application/x-wwww-form-urlencoded编码内容
eg:application/json,application/xml等(通过headlerAdapter配置的HttpMessageConverters来解析post data body,并绑定到相应的bean上,配置有FormHttpMessageConverter,可处理application/x-www-form-urlendcoded为 MultiValueMap<String,String>格式); - @RequestParam:将Request.getParameter()获取的String直接转换成简单类型(ConversionService配置的转换器来完成) get:queryString post:body date;
- @RequestHeader:将request请求header的值绑定到方法参数上;
- @CookieValue:将request请求中cookie的值绑定到方法参数上;
- @当RequstMapper的value为(uri template):path/{id}时 可用pathVariable 拿到{}里的值 @PathVariable(name=“id”) id name可指定uri template中的名称;
- @SessionAttributes: 处理HttpSession中attribute对象的值(value,type 两个属性);
- @ModelAttribute:
用于方法上:处理ReuqestMapper方法之前,为reuqest对象的model放置(“account”,account)
用在参数上:1:查询@SessionAttribute有无绑定对象 若无2:查询方法层面是否绑定该对象 若无3:将RequestMapper vlaue中 uri template的值绑定 - 总结参考链接:https://blog.csdn.net/dwn1209/article/details/51427118