风格1
语法结构
- 使用/方式分割参数.
- 使用{}包裹参数
- 在参数方法中 动态接收参数时使用特定注解@PathVariable
使用一个方法实现页面跳转
/*
url: /test/a
/test/b
*/
@RequestMapping("/test/{testMethod}") //{testMethod}动态接收a/b
public String test(@PathVariable String testMethod) {
return testMethod;
}
风格2
利用通用的url地址,实现不同的业务调用
// value:请求地址 method:指定接收请求的方式
@RequestMapping(value = "/user",method = RequestMethod.POST)
//@PostMapping("/user")
public String test(String text) {
return text;
}
//@RequestMapping(value = "/user",method = RequestMethod.POST)
//@GetMapping("/user")
总结
一般在工作中有2种用法.
作用1: 动态获取url路径中的参数
作用2: 以统一的url地址,不同的请求类型,实现不同业务的调用.
一般都会添加请求类型进行标识.为了安全.