我正在嘗試使用@ValidateWithMethod來驗證屬性。我有兩個非常不同的自定義驗證。我想把它們放在不同的方法中,這樣我可以有不同的信息。但是,放置兩個單獨的@ValidateWithMethod屬性會導致「重複註釋」編譯錯誤。橢圓形 - 使用不同消息的多重ValidateWithMethod /複雜自定義驗證?
在這種情況下你應該做什麼?
我正在嘗試使用@ValidateWithMethod來驗證屬性。我有兩個非常不同的自定義驗證。我想把它們放在不同的方法中,這樣我可以有不同的信息。但是,放置兩個單獨的@ValidateWithMethod屬性會導致「重複註釋」編譯錯誤。橢圓形 - 使用不同消息的多重ValidateWithMethod /複雜自定義驗證?
在這種情況下你應該做什麼?
我發現註釋語法有點棘手搞清楚,所以我加入一個例子:
@ValidateWithMethod.List(value={
@ValidateWithMethod(methodName="foo", parameterType=String.class, ignoreIfNull=true, message="FooError"),
@ValidateWithMethod(methodName="bar", parameterType=String.class, ignoreIfNull=true, message="BarError")
})
private String thing;
您可以使用@ValidateWithMethod.List
註釋在同一元素上聲明多個@ValidateWithMethod
。