1. pom引入
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
2. 异常处理
- 全局异常拦截处理 ```java package com.afei.unified.handler;
import com.afei.unified.common.ResultVO; import com.afei.unified.common.enums.ResultCodeEnum; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.validation.ObjectError; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.util.ArrayList; import java.util.List;
/**
- @author shihengfei
- @date 2020/8/7 15:39
@description: 全局异常处理类 */ @RestControllerAdvice @Slf4j public class GlobalExceptionHandler {
/**
自定义异常CustomException */ @ExceptionHandler(CustomException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public ResultVO