| | |
| | | import org.springframework.http.converter.HttpMessageNotReadableException; |
| | | import org.springframework.http.converter.HttpMessageNotWritableException; |
| | | import org.springframework.jdbc.BadSqlGrammarException; |
| | | import org.springframework.validation.ObjectError; |
| | | import org.springframework.web.bind.MethodArgumentNotValidException; |
| | | import org.springframework.web.bind.annotation.ExceptionHandler; |
| | | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| | | import org.springframework.web.multipart.MultipartException; |
| | | |
| | | import java.io.FileNotFoundException; |
| | | import java.io.IOException; |
| | | import java.net.BindException; |
| | | import java.sql.SQLException; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | @Slf4j |
| | |
| | | return Result.fail("抱歉不支持【" + e.getMessage() +"】后缀的文件!"); |
| | | } |
| | | |
| | | /** |
| | | * 参数检验 |
| | | */ |
| | | @ExceptionHandler({MethodArgumentNotValidException.class}) |
| | | public Result<?> methodArgumentNotValidException(MethodArgumentNotValidException e) { |
| | | List<ObjectError> allErrors = e.getBindingResult().getAllErrors(); |
| | | String message = allErrors.stream().map(s -> s.getDefaultMessage()).collect(Collectors.joining(";")); |
| | | return Result.fail(message); |
| | | } |
| | | |
| | | /** 其他错误 */ |
| | | @ExceptionHandler({Exception.class}) |
| | | public Result<?> exception(Exception e) { |