@@ -0,0 +1,3332 @@
+package com.nicefish.web.exception;%0A%0Aimport com.nicefish.common.constant.ResponseState;%0Aimport com.nicefish.common.constant.Result;%0Aimport org.springframework.beans.factory.annotation.Value;%0Aimport org.springframework.http.HttpStatus;%0Aimport org.springframework.http.MediaType;%0Aimport org.springframework.validation.FieldError;%0Aimport org.springframework.validation.ObjectError;%0Aimport org.springframework.web.HttpMediaTypeNotSupportedException;%0Aimport org.springframework.web.bind.MethodArgumentNotValidException;%0Aimport org.springframework.web.bind.annotation.ControllerAdvice;%0Aimport org.springframework.web.bind.annotation.ExceptionHandler;%0Aimport org.springframework.web.bind.annotation.ResponseBody;%0Aimport org.springframework.web.bind.annotation.ResponseStatus;%0A%0Aimport java.util.List;%0A%0A/**%0A * Created by sunye on 17/6/28.%0A */%0A@ControllerAdvice%0Aclass GlobalControllerExceptionHandler %7B%0A%0A%0A%0A    @Value(%22$%7Bdebug%7D%22)%0A    private boolean debug;%0A%0A    @ExceptionHandler%0A    @ResponseStatus(HttpStatus.BAD_REQUEST)%0A    @ResponseBody%0A    Result handleException(MethodArgumentNotValidException ex) %7B%0A        List%3CFieldError%3E fieldErrors = ex.getBindingResult().getFieldErrors();%0A        List%3CObjectError%3E globalErrors = ex.getBindingResult().getGlobalErrors();%0A        StringBuffer bf=new StringBuffer();%0A        fieldErrors.forEach(e-%3Ebf.append(e.getField()).append(%22, %22).append(e.getDefaultMessage()));%0A        globalErrors.forEach(e-%3Ebf.append(e.getObjectName()).append(%22,%22).append(e.getDefaultMessage()));%0A        return new Result(false,debug==true?bf.toString():null, ResponseState.RESPONSE_ILLEGAL_REQUEST.code);%0A    %7D%0A%0A%0A    /*@ExceptionHandler%0A    @ResponseStatus(HttpStatus.BAD_REQUEST)%0A    @ResponseBody%0A    Result getErrorMessage(HttpMessageNotReadableException ex) %7B%0A        Throwable mostSpecificCause = ex.getMostSpecificCause();%0A        StringBuffer bf=new StringBuffer();%0A        if (mostSpecificCause != null) %7B%0A            bf.append(mostSpecificCause.getClass().getName());%0A            bf.append(mostSpecificCause.getMessage());%0A            return new Result(false,bf.toString(),null);%0A        %7D%0A        return new Result(false,ex.getMessage(),null);%0A    %7D*/%0A%0A%0A%0A%0A    @ExceptionHandler%0A    @ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)%0A    @ResponseBody%0A    Result getErrorMessage(HttpMediaTypeNotSupportedException ex) %7B%0A        StringBuffer bf=new StringBuffer();%0A        bf.append(%22Unsupported content type: %22).append(ex.getContentType());%0A        bf.append(%22Supported content types: %22).append(MediaType.toString(ex.getSupportedMediaTypes()));%0A        return new Result(false,debug==true?bf.toString():null,ResponseState.RESPONSE_UNSUPPORTED_MEDIA_TYPE.code);%0A    %7D%0A%0A%0A%0A%0A    @ExceptionHandler%0A    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)%0A    @ResponseBody%0A    Result handleException(RuntimeException ex)%7B%0A        Throwable mostSpecificCause = ex.getCause();%0A        StringBuffer bf=new StringBuffer();%0A        if (mostSpecificCause != null) %7B%0A            bf.append(mostSpecificCause.getClass().getName());%0A            bf.append(mostSpecificCause.getMessage());%0A            return new Result(false,debug==true?bf.toString():null, ResponseState.RESPONSE_SYSTEM_ERROR.code);%0A        %7D%0A        return new Result(false,debug==true?ex.getMessage(): null,ResponseState.RESPONSE_SYSTEM_ERROR.code);%0A    %7D%0A%0A%0A%0A%0A%7D%0A

add exception handller