@Override protected ResponseEntity<Object> handleMissingPathVariable(MissingPathVariableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { String name = ex.getVariableName(); CommonResponse<?> body = CommonResponse.fail(CommonResponse.INTERNAL_ERROR, "缺少路径参数: " + name); return handleExceptionInternal(ex, body, headers, status, request); }
/** * Customize the response for MissingPathVariableException. * @param ex the exception * @param headers the headers to be written to the response * @param status the selected response status * @param request the current request * @return the RestErrorResponse Object * @since 4.2 */ @Override protected ResponseEntity<Object> handleMissingPathVariable(MissingPathVariableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { String error = "Path Variable : " + ex.getVariableName() + " is missing"; return buildResponseEntity(new RestErrorResponse(HttpStatus.BAD_REQUEST, error, ex)); }
StringBuilder builder = new StringBuilder("路径字段"); MissingPathVariableException ex = (MissingPathVariableException) exception; builder.append(ex.getVariableName()); builder.append("校验不通过"); failedResponseBuilder.exception(builder.toString()).msg(ex.getMessage());