@RequestMapping

作者: xzz4632 | 来源:发表于2019-07-09 14:35 被阅读0次

1. RequestMapping注解:

  • @RequestMapping:
    接收所有类型的请求
  • @GetMapping:
    接收GET请求
  • @PostMapping:
    接收POST请求
  • @PutMapping:
    接收PUT请求
  • @DeleteMapping:
    接收DELETE请求
  • @PatchMapping:
    接收PATCH请求

2. 注解参数

2.1 value

定义请求uri. 同path

2.2 path

除了定义确定的uri以外还可以使用以下符号:

  • ?: 匹配一个字符
  • *: 在一个路径中匹配0个或多个字符
  • **: 匹配一个或多个路径段.
  • {}: 在路径中定义路径变量.
    可以用@PathVariable注解访问这个变量的值. 如@GetMapping("/pets/{petId}").
  • {varName:regex}: 定义一个正则表达式的URI变量. 只有当给定参数匹配正则表达式时才会匹配请求.
  • ${}: 引用本地,系统, 环境变量.

注:spring mvc默认提供了.作为请求的后缀. 但是这在使用URI变量时可能会引发歧义.

2.3 params

定义参数过滤条件, String数组类型.

  • 参数名(!)=参数值
    存在某个参数且值等于或不等于指定值时匹配请求.

  • (!)参数名
    存在或不存在某个参数时匹配.

2.4 headers

params.
注:headers在接收content-type, accept参数时还支持通配符*. *号用于匹配/后面的部分.

2.5 consumes

指定可消费的Media Type, 即匹配content-type参数. 可用!表示否定. 即除此之外.

consumes = "text/plain"
 consumes = {"text/plain", "application/*"}
consumes = "!text/plain" // 表示否定
2.6 produces

可生成的Media Type. 匹配请求的Accept参数. 可用!表示否定.

produces = "text/plain"
 produces = {"text/plain", "application/*"}
 produces = MediaType.APPLICATION_JSON_UTF8_VALUE
2.7 name

为这个映射分配一个名称

2.8 method

定义这个请求的请求方式.

相关文章

  • SpringMVC (1)

    SpringMVC: 一、RequestMapping 1、在方法上使用@RequestMapping注解...

  • Spring MVC的注解

    一@RequestMapping注解,是映射注解,根据@RequestMapping("parameter")里的...

  • @GetMapping和@PostMapping 和@Reque

    @GetMapping具体来说就是@RequestMapping的简写@RequestMapping(method...

  • @RequestMapping

    使用@RequestMapping映射处理请求: 一. Spring MVC使用@RequestMapping注解...

  • @RequestMapping

    @RequestMapping RequestMapping注解六个属性 1、 value, method; va...

  • Spring Boot 学习之路三 Controller

    @RequestMapping 的使用 @RequestMapping 可以放在Controller 的类上,也可...

  • @RequestMapping

    1. RequestMapping注解: @RequestMapping:接收所有类型的请求 @GetMappin...

  • @RequestMapping

    1.窄化请求,在controller类前加@RequestMapping注解 //商品信息修改页面@Request...

  • @RequestMapping

    @RequestMapping Value:请求路径,可以是数组 Method:请求类型,如HTTP的GET请求或...

  • @RequestMapping

    @RequestMapping: RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上。...

网友评论

    本文标题:@RequestMapping

    本文链接:https://www.haomeiwen.com/subject/czxxkctx.html