How to customize @RequestParam error 400 response in Spring MVC

前端 未结 2 575
心在旅途
心在旅途 2020-12-16 14:12

Is there a way to customize what gets displayed when a required @RequestParam is not sent to the request handler? I always get HTTP Status 400 with a descriptio

2条回答
  •  旧时难觅i
    2020-12-16 14:47

    How I solved my problem:

    @ResponseBody
    @ExceptionHandler(MissingServletRequestParameterException.class)
    public Object missingParamterHandler(Exception exception) {
        // exception handle while specified arguments are not available requested service only. it handle when request is as api json service       
        return  new HashMap() {{ put("result", "failed"); put("type", "required_parameter_missing");}};
    } 
    

提交回复
热议问题