add
This commit is contained in:
@ -1,8 +1,11 @@
|
||||
package com.qiaoba.common.base.entity;
|
||||
|
||||
import com.qiaoba.common.base.validate.AddGroup;
|
||||
import com.qiaoba.common.base.validate.EditGroup;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@ -43,6 +46,7 @@ public class BaseEntity implements Serializable {
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Size(max = 500, message = "备注不能超过{max}个字符", groups = {AddGroup.class, EditGroup.class})
|
||||
private String remark;
|
||||
|
||||
}
|
||||
|
@ -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