springboot分組檢驗

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"; 
    }

二者位置不同

感謝:https://www.jianshu.com/p/211aa556a4fa

https://my.oschina.net/cloudcross/blog/1926807

https://www.cnblogs.com/kangshuolei/p/12091204.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章