• @RequestMapping注解


    @RequestMapping注解的源码

    @Target({ElementType.TYPE, ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @Mapping
    public @interface RequestMapping {
        String name() default "";
    
        @AliasFor("path")
        String[] value() default {};
    
        @AliasFor("value")
        String[] path() default {};
    
        RequestMethod[] method() default {};
    
        String[] params() default {};
    
        String[] headers() default {};
    
        String[] consumes() default {};
    
        String[] produces() default {};
    }

    @RequestMapping注解的功能

    @RequestMapping注解的作用就是将请求和处理请求的控制器方法关联起来,建立映射关系。

    SpringMVC 接收到指定的请求,就会来找到在映射关系中对应的控制器方法来处理这个请求。
    该注解可以标识在类和方法上。

    @RequestMapping注解的位置

    @RequestMapping标识一个类:设置映射请求的请求路径的初始信息

    @RequestMapping标识一个方法:设置映射请求请求路径的具体信息

    如果有请求路径的初始信息,则先设置请求路径的初始信息才能设置请求路径的具体信息。

    比如,想从index的超链接跳转到welcome页面:

    index.html

    <!DOCTYPE html>
    <html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>首页</title>
    </head>
    <body>
        <h1>首页</h1>
        <a th:href="@{/testRequestMapping}">访问welcome页面 </a>
    </body>
    </html>

    https://www.cnblogs.com/gonghr/p/15192887.html

    故乡明
  • 相关阅读:
    并发编程
    网络与WEB 编程
    包和模块
    元编程
    类和对象
    【算法题 14 LeetCode 147 链表的插入排序】
    剑指offer面试54题
    剑指offer 面试51题
    剑指offer 面试3题
    剑指offer 面试52题
  • 原文地址:https://www.cnblogs.com/luweiweicode/p/15203193.html
Copyright © 2020-2023  润新知