RequestMapping

RequestMapping

  • @RequestMapping注解用于映射url到控制器类或一个特定的处理程序方法。可用于类或方法上。用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径。
  • 只注解在方法上面
@Controller
public class TestController {
   @RequestMapping("/h1")
   public String test(){
       return "test";
  }
}

访问路径:http://localhost:8080/SpringMVC_annotation_war_exploded/h1

  • 同时注解类与方法
@Controller
@RequestMapping("/t1")
public class TestController {
   @RequestMapping("/h1")
   public String test(){
       return "test";
  }
}

访问路径:http://localhost:8080/SpringMVC_annotation_war_exploded/t1/h1

posted @ 2021-06-29 09:35  saxon宋  阅读(379)  评论(0)    收藏  举报