问答详情
源自:2-4 统一异常处理(上)

金额比传啊

@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/"
}

提问者:forever_zsjl 2017-11-08 18:05

个回答

  • mjka5632
    2017-11-30 16:50:14
    已采纳

    没问题了吧,不return 肯定不行的

  • forever_zsjl
    2017-11-08 19:25:50

    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,记得没设啊!