Bootstrap

Spring@RequestMapper与接口方法参数注解

@RequestMapper六个属性及七个方法参数注解

此乃个人笔记,适合有一定了解的人看,若看不懂,可点击参考链接,里面有每个属性与注解的具体代码示例

@RestController

@Requestbody和@Controller的结合体

@ReuqestMapper

一句话概括:六个参数 value(请求路径) method(请求类型) produces(返回数据类型) consumes(请求数据类型) params(请求参数) heads(请求头)

  1. value:请求路径;
  2. mothod:请求类型 get post put delete;
  3. consumes:指定处理请求的提交内容类型(content-type)eg:application/json text/html;
  4. produces:指定返回数据类型,request请求头(accept)类型中包含该指定类型,才返回;
  5. params:指定request中必须包含指定参数值,才让方法处理;
  6. headers:指定request包含指定header值,才处理;
  7. 参考链接:https://blog.csdn.net/longcccvv/article/details/54289022

方法参数

常用:@RequestBody @RequestParam @RequestHeader @PathVariable

  1. @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>格式);
  2. @RequestParam:将Request.getParameter()获取的String直接转换成简单类型(ConversionService配置的转换器来完成) get:queryString post:body date;
  3. @RequestHeader:将request请求header的值绑定到方法参数上;
  4. @CookieValue:将request请求中cookie的值绑定到方法参数上;
  5. @当RequstMapper的value为(uri template):path/{id}时 可用pathVariable 拿到{}里的值 @PathVariable(name=“id”) id name可指定uri template中的名称;
  6. @SessionAttributes: 处理HttpSession中attribute对象的值(value,type 两个属性);
  7. @ModelAttribute:
    用于方法上:处理ReuqestMapper方法之前,为reuqest对象的model放置(“account”,account)
    用在参数上:1:查询@SessionAttribute有无绑定对象 若无2:查询方法层面是否绑定该对象 若无3:将RequestMapper vlaue中 uri template的值绑定
  8. 总结参考链接:https://blog.csdn.net/dwn1209/article/details/51427118

笔记在idea的截图在这里插入图片描述

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;