使用@RequestParam
例如:http://localhost:8080/springboot/hello?id=123
@GetMapping(value = "/hello")
public String Demo1(@RequestParam(value="id") String id)){
...
}
使用@PathVariable
例如:http://localhost:8080/springboot/hello/123
@GetMapping(value = "/hello/{id}")
public String Demo2(@PathVariable(value="id") String id)){
...
}
- 关键点不同的是@RequestParam 是从request里面拿取值,而 @PathVariable 是从一个URI里提取变量的值