Java Code Examples for org.springframework.web.bind.MissingPathVariableException

Following code examples demonstrate how to use org.springframework.web.bind.MissingPathVariableExceptionfrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.web.bind.MissingPathVariableExceptionand various code implementation of this class.

    public BaseResponse handle(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws IOException {
        String message = "请求报错";
        if(ex instanceof MissingServletRequestParameterException){
            MissingServletRequestParameterException e = (MissingServletRequestParameterException) ex;
            message = "缺少参数:"+e.getParameterName();
        }else if(ex instanceof MissingPathVariableException){
            MissingPathVariableException e = (MissingPathVariableException) ex;
            message = "缺少参数:"+e.getVariableName();
        }
        BaseResponse res = new ConstraintsResponse();
        res.setMessage(message);
        return res;
    } 


        if (e instanceof RequestParamMissingException) {
            return ResponseUtil.requestParamMissing();
        } else if (e instanceof MissingRequestHeaderException){
            return ResponseUtil.requestHeaderMissing(e.getLocalizedMessage());
        } else if (e instanceof MissingPathVariableException) {
            return ResponseUtil.pathVariableMissing(e.getLocalizedMessage());
        } 

  public Errormessage missingPathVariableException() {
    Errormessage m = new Errormessage();
    return m;
  } 

Advertisement
Javadoc
ServletRequestBindingException subclass that indicates that a path variable expected in the method p

arameters of an @RequestMapping method is not present among the URI variables extracted from the URL. Typically that means the URI template does not match the path variable name declared on the method parameter. @author Rossen Stoyanchev @since 4.2 @see MissingMatrixVariableException

Read More
Advertisement