springboot分组检验

59 阅读1分钟

1、在jsronrpc里面用法
1、1在实体类中定义

@NotNull(message = "协议版本号不能为空",groups ={Save.class,Query.class} )
    private Integer agreement_version;
    public interface Save {
    }
    public interface Query {
    }

1、2在接口层添加注解

@Validated({AgreementRecord.Query.class})
    AgreementRecordVO queryAggrement(@Valid AgreementRecord agreementRecord);

2、在controler里面注解这样添加

@RequestMapping(value = "/healthy1", method = RequestMethod.POST)
    public
    @ResponseBody
    @Validated({AgreementRecord.Save.class})
    String healthy1(@Valid @RequestBody AgreementRecord aggrementRecord) {
        return "success"; 
    }

二者位置不同
感谢:Java Bean Validation分组校验 - 简书
使用Hibernate-Validator优雅的验证RESTful Web Services的参数 - 默宿的个人空间 - OSCHINA - 中文开源技术交流社区
www.cnblogs.com/kangshuolei…