@RequestParam(required = true)的誤區

先說結論:required = true是在前端沒有傳參數的時候報錯,並不能防止參數爲空。
考慮一下代碼:

@GetMapping("/userInfo")
    public void userInfo(@RequestParam(required = true) Integer id) {
           ...
    }

如果請求如下就會報400錯誤:

http://localhost:8088/userInfo

但構造以下請求,可以使id爲空:

http://localhost:8088/userInfo?id=
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章