add
This commit is contained in:
@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@ -69,4 +70,17 @@ public class ExceptionAdvice {
|
||||
public AjaxResult handlerValidException(BindException e) {
|
||||
return AjaxResult.error(Objects.isNull(e.getBindingResult().getFieldError()) ? e.getMessage() : e.getBindingResult().getFieldError().getDefaultMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数校验
|
||||
*
|
||||
* @param e ConstraintViolationException
|
||||
* @return AjaxResult
|
||||
*/
|
||||
@ExceptionHandler({ConstraintViolationException.class})
|
||||
@ResponseBody
|
||||
public AjaxResult handlerValidException(ConstraintViolationException e) {
|
||||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user