@NotNull(message = "金额不可为空")
private Integer money;
不传金额就报错
{
"timestamp": 1510133988768,
"status": 500,
"error": "Internal Server Error",
"exception": "javax.validation.ConstraintViolationException",
"message": "Validation failed for classes [com.girl.domain.Girl] during persist time for groups [javax.validation.groups.Default, ]\nList of constraint violations:[\n\tConstraintViolationImpl{interpolatedMessage='金额不可为空', propertyPath=money, rootBeanClass=class com.girl.domain.Girl, messageTemplate='金额不可为空'}\n]",
"path": "/girls/"
}
没问题了吧,不return 肯定不行的
public Result girlAdd(@Valid Girl girl,BindingResult bindingResult){
if(bindingResult.hasErrors()){
Result result = new Result();
result.setCode(1);
result.setMsg(bindingResult.getFieldError().getDefaultMessage());
return result;
}
这我没有return,记得没设啊!