1. RequestMapping注解,源码如下图:
![](https://img.haomeiwen.com/i12842279/4dd48ab117bf7379.png)
1.1 RequestMapping的作用介绍
@RequestMapping注解的主要作用是国际表示请求路径与方法的映射关系,如下图案列
![](https://img.haomeiwen.com/i12842279/c58cdf74da950c12.png)
上面案列的@RequestMapping注解的value是/hello在sayhello()方法上,表示用户请求http://localhost:8085/hello的时候,该请求酱油sayHello()方法拦截处理.
1.2 @RequestMapping作用位置
该注解可以作用在方法和类上.
作用在类上:第一季的访问目录.
作用在方法上:第二季的访问目录.如下图所示:
![](https://img.haomeiwen.com/i12842279/ab434c7d411e2fd2.png)
此时的请求地址则改变成了 http://localhost:8085/hello/say
1.3 @RequestMapping的属性
path value method params headers等属性
其中path和value的属性用法是一样的,如下图所示:
![](https://img.haomeiwen.com/i12842279/679cc502c78a89e8.png)
method方法可以约束提交的方式 加了method = RequestMethod.POST 则只能用post方式提交
加了method = RequestMethod.get,则只能用get方法提交``
![](https://img.haomeiwen.com/i12842279/740721e4793c53c5.png)
params指定限制请求参数的条件
![](https://img.haomeiwen.com/i12842279/d3767438c91e6140.png)
![](https://img.haomeiwen.com/i12842279/e10eb8a23998725e.png)
![](https://img.haomeiwen.com/i12842279/9e6c01fabb1c9198.png)
headers 发送的请求中必须包含的请求头
![](https://img.haomeiwen.com/i12842279/5fc63210bbd4a166.png)
![](https://img.haomeiwen.com/i12842279/d3eaf07aa7d329e8.png)
网友评论