@RequestParam
@RequestMapping(value = "/test", method = {RequestMethod.POST, RequestMethod.GET})
public String test(@RequestParam("name") String name) {
System.out.println(name);
return name;
}
http://localhost:端口号/test?name=345
@PathVariable
@RequestMapping(value = "/test/{name}", method = {RequestMethod.POST, RequestMethod.GET}) public String test(@PathVariable("name") String name) { System.out.println(name); return name; }
localhost:22499/user/test/zhangsan
两个注解可以组合使用
- 注解 PathVariable RequestParam 接口注解pathvariable requestparam接口 注解pathvariable requestparam常用 注解requestparam pathvariable pathparam pathvariable requestparam requestbody requestparam pathvariable springmvc pathvariable requestparam场景param 注解pathvariable作用 requestparam pathvariable 注解requestparam参数 参数 注解requestparam函数