1. @Data
    2. @Accessors(chain = true)
    3. public class WhiteAEntity {
    4. @Matcher({"a","b","c","null"})
    5. private String name;
    6. private String address;
    7. }

    注意:测试代码这里全部采用Spock测试框架进行工具方面的测试,主要是为了方便

    1. def "只有指定的值才能通过"() {
    2. given:
    3. WhiteAEntity entity = new WhiteAEntity()
    4. entity.setName(name as String)
    5. expect:
    6. boolean actResult = MkValidators.check(entity)
    7. if (!actResult) {
    8. println MkValidators.getErrMsgChain()
    9. }
    10. Assert.assertEquals(result, actResult)
    11. where:
    12. name | result
    13. "a" | true
    14. "b" | true
    15. "c" | true
    16. null | true
    17. "d" | false
    18. }