参数校验
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@ControllerAdvice
public class ExceptionConfig {
@ResponseBody
@ExceptionHandler(value = MethodArgumentNotValidException.class)
public RestResultDTO argumentExceptionHandler(MethodArgumentNotValidException exception) {
String message = exception.getBindingResult().getFieldError().getDefaultMessage();
return RestResultGenerator.ERROR4Vue(message);
}
}
@Data
public class User4VueDTO {
@Valid
UserDTO userDTO;
@NotEmpty
List<String> roleguids;
}
@Data
public class UserDTO {
String guid;
@NotEmpty(message = "我empty")
String code;
}