0%

spring | @RequestParam

@RequestParam 注解的用法

demo

1
2
3
4
@GetMapping("/list")
public String test(@RequestParam int userId) {
return "list";
}

讲解如下

1
2
3
@RequestParam(required = false)设置为非必传。因为required值默认是true,所以默认必传
@RequestParam("userId")或者@RequestParam(value = "userId")指定参数名。
@RequestParam(defaultValue = "0")指定参数默认值

用法如下

1
2
3
4
@GetMapping("/list")
public String test(@RequestParam(value = "userId", defaultValue = "0", required = false) int userId) {
return "list";
}
请我喝杯咖啡吧~