Spring BindingResult獲取不到結果可能的原因之一 參數順序 沒有緊挨着校驗參數

@Valid或@Validate的參數後必須緊挨着一個BindingResult 參數,否則spring會在校驗不通過時直接拋出異常

    public InternalResponseVo updateSource(@Validated @RequestBody(required = false) SourceValidator sourceValidator, @PathVariable int id, BindingResult bindingResult) {}

如果出現錯誤會直接拋出異常,方法不會執行。只需要修改bindingresult的位置使其挨着校驗入參即可

修改後:

    public InternalResponseVo updateSource(@Validated @RequestBody(required = false) SourceValidator sourceValidator, BindingResult bindingResult, @PathVariable int id){}

 

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