@Data
@Accessors(chain = true)
public class TypeEntity {
/**
* 没有必要设置type
*/
@Matcher(type = Integer.class)
private Integer data;
@Matcher(type = CharSequence.class)
private String name;
@Matcher(type = {Integer.class, Float.class})
private Object obj;
@Matcher(type = Number.class)
private Object num;
}
测试代码
def "测试不明写类继承关系1"() {
given:
TypeEntity entity = new TypeEntity().setObj(obj)
expect:
boolean actResult = MkValidators.check(entity, "obj")
if (!result) {
println MkValidators.getErrMsgChain()
}
Assert.assertEquals(result, actResult)
where:
obj | result
'c' | false
"abad" | false
1232 | true
1232l | false
1232f | true
12.0f | true
-12 | true
}
注意:
- 如果设置的类型不是属性的类型或者父类则会报错
- 如果为具体的类型,则再设置与其相同的类型,则没有必要,就像上面的data属性