@RequestParam(required = true)时,前端必须传参数 否则报400错误
@GetMapping("/userInfoTest")
public void userInfoTest(@RequestParam(required = true) String id) {
...
}
请求如下就会报400错误:
http://localhost:8088/userInfoTest
但是这样就不会报错:
http://localhost:8088/userInfoTest?id=
@RequestParam(required = false)表示前端不传参数的时候,会将参数置为null。因此假如参数是int这种不能赋值为null的类型,就可能会报错