springMVC RequestMapping
1 加的地方
1.可以加在类上 用于模块
2.可以加在方法上 用于路径
package com.cj.mvc.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("test") public class TestController { @RequestMapping("test1") public String test1(){ return "test1"; } }
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h1>首页</h1> <a th:href="@{/test/test1}">测试1</a> </body> </html>
2 value属性
可以匹配多个
package com.cj.mvc.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("test") public class TestController { @RequestMapping(value = {"test1","test2"}) public String test1(){ return "test1"; } }
3 method
@RequestMapping(value = {"test1","test2"},method = {RequestMethod.GET})
4 派生
@GetMapping("test3")
@PostMapping
@DeleteMapping
5 Params
@GetMapping(value = "test3",params = {"username"})
public String test3(){
    return "test3";
}
<a th:href="@{/test/test3(username='admin')}">测试3</a>
6 ant风格
?匹配任意单个字符
* 匹配任意的0个或者多个字符
** 匹配任意的一层或多层目录
7 占位符
@GetMapping("/test5/{id}")
public String test5(@PathVariable("id") Integer id){
    return "test5";
}
                    
                
                
            
        
浙公网安备 33010602011771号