源码:
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Mapping
public @interface RequestMapping { } 作用: 用于建立请求URL和处理请求方法之间的对应关系。
/** Copyright 2002-2017 the original author or authors.** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**      http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package org.springframework.web.bind.annotation;import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;import org.springframework.core.annotation.AliasFor;/*** Annotation for mapping web requests onto specific handler classes and/or* handler methods.** <p>Handler methods annotated with this annotation can have very flexible* signatures. The exact details of the supported method arguments and return* values depend on the specific* {@link org.springframework.stereotype.Controller @Controller} model supported.* Both Spring Web MVC and Spring WebFlux support this annotation with some* differences. More details are available in the Spring Framework reference.** <p><b>NOTE:</b> {@code @RequestMapping} will only be processed if an* an appropriate {@code HandlerMapping}-{@code HandlerAdapter} pair* is configured. If you are defining custom {@code HandlerMappings} or* {@code HandlerAdapters}, then you need to add {@code RequestMappingHandlerMapping}* and {@code RequestMappingHandlerAdapter} to your configuration.</code>.** <p><b>NOTE:</b> When using controller interfaces (e.g. for AOP proxying),* make sure to consistently put <i>all</i> your mapping annotations - such as* {@code @RequestMapping} and {@code @SessionAttributes} - on* the controller <i>interface</i> rather than on the implementation class.** @author Juergen Hoeller* @author Arjen Poutsma* @author Sam Brannen* @since 2.5* @see GetMapping* @see PostMapping* @see PutMapping* @see DeleteMapping* @see PatchMapping* @see RequestParam* @see RequestAttribute* @see PathVariable* @see ModelAttribute* @see SessionAttribute* @see SessionAttributes* @see InitBinder* @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter* @see org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter*/
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Mapping
public @interface RequestMapping {/*** Assign a name to this mapping.* <p><b>Supported at the type level as well as at the method level!</b>* When used on both levels, a combined name is derived by concatenation* with "#" as separator.* @see org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder* @see org.springframework.web.servlet.handler.HandlerMethodMappingNamingStrategy*/String name() default "";/*** The primary mapping expressed by this annotation.* <p>This is an alias for {@link #path}. For example* {@code @RequestMapping("/foo")} is equivalent to* {@code @RequestMapping(path="/foo")}.* <p><b>Supported at the type level as well as at the method level!</b>* When used at the type level, all method-level mappings inherit* this primary mapping, narrowing it for a specific handler method.*/@AliasFor("path")String[] value() default {};/*** In a Servlet environment only: the path mapping URIs (e.g. "/myPath.do").* Ant-style path patterns are also supported (e.g. "/myPath/*.do").* At the method level, relative paths (e.g. "edit.do") are supported within* the primary mapping expressed at the type level. Path mapping URIs may* contain placeholders (e.g. "/${connect}")* <p><b>Supported at the type level as well as at the method level!</b>* When used at the type level, all method-level mappings inherit* this primary mapping, narrowing it for a specific handler method.* @see org.springframework.web.bind.annotation.ValueConstants#DEFAULT_NONE* @since 4.2*/@AliasFor("value")String[] path() default {};/*** The HTTP request methods to map to, narrowing the primary mapping:* GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE, TRACE.* <p><b>Supported at the type level as well as at the method level!</b>* When used at the type level, all method-level mappings inherit* this HTTP method restriction (i.e. the type-level restriction* gets checked before the handler method is even resolved).*/RequestMethod[] method() default {};/*** The parameters of the mapped request, narrowing the primary mapping.* <p>Same format for any environment: a sequence of "myParam=myValue" style* expressions, with a request only mapped if each such parameter is found* to have the given value. Expressions can be negated by using the "!=" operator,* as in "myParam!=myValue". "myParam" style expressions are also supported,* with such parameters having to be present in the request (allowed to have* any value). Finally, "!myParam" style expressions indicate that the* specified parameter is <i>not</i> supposed to be present in the request.* <p><b>Supported at the type level as well as at the method level!</b>* When used at the type level, all method-level mappings inherit* this parameter restriction (i.e. the type-level restriction* gets checked before the handler method is even resolved).* <p>Parameter mappings are considered as restrictions that are enforced at* the type level. The primary path mapping (i.e. the specified URI value)* still has to uniquely identify the target handler, with parameter mappings* simply expressing preconditions for invoking the handler.*/String[] params() default {};/*** The headers of the mapped request, narrowing the primary mapping.* <p>Same format for any environment: a sequence of "My-Header=myValue" style* expressions, with a request only mapped if each such header is found* to have the given value. Expressions can be negated by using the "!=" operator,* as in "My-Header!=myValue". "My-Header" style expressions are also supported,* with such headers having to be present in the request (allowed to have* any value). Finally, "!My-Header" style expressions indicate that the* specified header is <i>not</i> supposed to be present in the request.* <p>Also supports media type wildcards (*), for headers such as Accept* and Content-Type. For instance,* <pre class="code">* @RequestMapping(value = "/something", headers = "content-type=text/*")* </pre>* will match requests with a Content-Type of "text/html", "text/plain", etc.* <p><b>Supported at the type level as well as at the method level!</b>* When used at the type level, all method-level mappings inherit* this header restriction (i.e. the type-level restriction* gets checked before the handler method is even resolved).* @see org.springframework.http.MediaType*/String[] headers() default {};/*** The consumable media types of the mapped request, narrowing the primary mapping.* <p>The format is a single media type or a sequence of media types,* with a request only mapped if the {@code Content-Type} matches one of these media types.* Examples:* <pre class="code">* consumes = "text/plain"* consumes = {"text/plain", "application/*"}* </pre>* Expressions can be negated by using the "!" operator, as in "!text/plain", which matches* all requests with a {@code Content-Type} other than "text/plain".* <p><b>Supported at the type level as well as at the method level!</b>* When used at the type level, all method-level mappings override* this consumes restriction.* @see org.springframework.http.MediaType* @see javax.servlet.http.HttpServletRequest#getContentType()*/String[] consumes() default {};/*** The producible media types of the mapped request, narrowing the primary mapping.* <p>The format is a single media type or a sequence of media types,* with a request only mapped if the {@code Accept} matches one of these media types.* Examples:* <pre class="code">* produces = "text/plain"* produces = {"text/plain", "application/*"}* produces = "application/json; charset=UTF-8"* </pre>* <p>It affects the actual content type written, for example to produce a JSON response* with UTF-8 encoding, {@code "application/json; charset=UTF-8"} should be used.* <p>Expressions can be negated by using the "!" operator, as in "!text/plain", which matches* all requests with a {@code Accept} other than "text/plain".* <p><b>Supported at the type level as well as at the method level!</b>* When used at the type level, all method-level mappings override* this produces restriction.* @see org.springframework.http.MediaType*/String[] produces() default {};}
package com.learn.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;// 控制器类
@Controller
@RequestMapping(path="/user")
public class HelloController {/*** 入门案例* @return*/@RequestMapping(path="/hello")public String sayHello(){System.out.println("Hello StringMVC");return "success";}/*** RequestMapping注解* @return*/@RequestMapping(value="/testRequestMapping",params = {"username=heihei"},headers = {"Accept"})public String testRequestMapping(){System.out.println("测试RequestMapping注解...");return "success";}}

RequestMapping注解的作用相关推荐

  1. SpringMVC RequestMapping注解详解

    2019独角兽企业重金招聘Python工程师标准>>> @RequestMapping注解的作用是对用户的请求映射到指定的控制器或方法,所以该注解可以用来修饰类和方法,在Reques ...

  2. (续)SSM整合之springmvc笔记(@RequestMapping注解)(P124-130)

    目录 @RequestMapping注解 一.准备工作 1 新建spring_mvc_demo    com.atguigu 2. 导入依赖 3 .添加web模板 4 . 在web.xml里面进行进行 ...

  3. RequestMapping注解

    目录 1. @RequestMapping注解的功能 2. @RequestMapping注解的位置 3. @RequestMapping注解的value属性 4. @RequestMapping注解 ...

  4. requestmapping注解作用_Java高级架构师-Spring 注解编程之注解属性别名与覆盖

    欢迎关注头条号:Java小野猫 注解属性方法 在进入了解 Spring 注解属性功能之前,我们先看一个正常 Java 注解. 在注解中,属性方法与其他类/接口方法写法类似,但是存在一些区别. 注解属性 ...

  5. @RequestMapping注解中的produces属性的作用

    关于@RequestMapping注解 这个注解的使用方法相信大家都知道,可以写在类或者方法上,指定请求的url路径,最近在使用的时候发现了一些原来没有注意的地方,特此记录 记录一:一个注解可以设置多 ...

  6. spring mvc -@RequestMapping注解详解

    https://www.cnblogs.com/caoyc/p/5635173.html @RequestMapping参数说明: value:定义处理方法的请求的URL地址(重点): method: ...

  7. SpringMVC框架 学习DAY_03:@RequestMapping注解/拦截器与过滤器

    1. 关于@RequestMapping注解 在控制器中,在处理请求的方法之前添加@RequestMapping注解,可以配置请求路径与处理请求的方法的映射关系! 在@RequestMapping注解 ...

  8. Spring MVC @RequestMapping注解详解

    @RequestMapping 参数说明 value:定义处理方法的请求的 URL 地址.(重点) method:定义处理方法的 http method 类型,如 GET.POST 等.(重点) pa ...

  9. spring boot常用注解的作用

    Controller层注解 @Controller和@RestController的区别 @RestController注解相当于@ResponseBody + @Controller合在一起的作用 ...

最新文章

  1. 码易众包:软件开发众包的未来不能只靠等待和呐喊
  2. mfc 弹框只出现一次_只出现一次的数字
  3. 预期的异常规则和模拟静态方法– JUnit
  4. python 方程组 整数解_用Python语言求解线性整数方程组
  5. Fast Paxos
  6. Oracle从零开始4——数据库更新操作
  7. 前端性能优化的重要方案:图片懒加载
  8. 现实问题从数学化到离散化再到程序化
  9. Paper Read: Robust Deep Multi-modal Learning Based on Gated Information Fusion Network
  10. CRM用户体验对比(二):导入联系人—— 百会、WorkXP
  11. Port-A-Thon
  12. mysql gbk转utf8_MySQL字符集GBK转换到UTF8
  13. VirusTotal 为 Chrome 和 Firefox 发布 VT4Browsers 扩展
  14. 个人和企业拥有专利的25个好处!
  15. B - Molar mass UVA - 1586
  16. Google Colab中把pyth3.7版本更换成python2.7
  17. mysql b树_为什么 MongoDB 索引选择B树,而 Mysql 选择B+树(精干总结)
  18. 梅特勒电子天平维修触摸屏维修XS205
  19. 怎么使用迅捷文字转语音软件转换文字
  20. [天方夜谭]上帝夜访点点

热门文章

  1. SpringMVC解决跨域的两种方案
  2. 2440按键中断编程
  3. UVa 103 - Stacking Boxes(dp求解)
  4. HGE重新架构资源管理
  5. kafka整理笔记笔记
  6. CSDN、博客园等6大技术博客平台的写作体验测评
  7. flex页面布局练习--知乎
  8. 教你如何用node.js开发微信公众号(一)
  9. gmock学习01---Linux配置gmock
  10. 以对象的形式动态获取宽高