来自javax@Pattern的不同验证消息
我的类用户有两个带电话的字段,一个用于移动电话,另一个用于工作电话来自javax@Pattern的不同验证消息,java,validation,Java,Validation,我的类用户有两个带电话的字段,一个用于移动电话,另一个用于工作电话 @Valid @NotNull @JsonView({View.Detail.class}) private Phone workPhone; @Valid @JsonView({View.Detail.class}) private Phone mobilePhone; class Phone具有由@Pattern验证的字段号 @JsonView({View.Country.class, View.Detail.class
@Valid
@NotNull
@JsonView({View.Detail.class})
private Phone workPhone;
@Valid
@JsonView({View.Detail.class})
private Phone mobilePhone;
class Phone具有由@Pattern验证的字段号
@JsonView({View.Country.class, View.Detail.class, View.Summary.class})
@NotBlank(message = "missing.phone")
@Pattern(regexp = Regexps.ONLY_DIGITS, message = ProfileMessages.MOBILE_PHONE_INVALID)
@Length(max = 25, message = CommonMessages.LENGTH_MAX)
private String number;
我的问题是@Pattern的message属性现在是profileMessages.MOBILE\u PHONE\u无效,该属性仅适用于移动电话。是否有任何方法可以动态更改此消息,而无需创建新类?当我尝试添加新字段并将其用作消息填充时,它显示了一个错误,即它应该是常量。为什么不在
用户
类中进行验证,而不是在电话
中进行验证?顺便说一句,在注释中,您只能使用常量,无法将变量放入其中。class Phone还有其他字段