Bean Validation and error messages at .properties file

自作多情 提交于 2019-11-28 09:31:13
Hardy

You are having two problems here. First, the location of the ValidationMessages.properties file. It has to be in the root of the classpath, so move it into WEB-INF/classes Your second problems are the message keys. The default message key for the Pattern constraint for example is {javax.validation.constraints.Pattern.message}. In your case you want to specify the message parameter in the @Pattern annotation:

@Pattern(regexp=".+@.+\\.[a-z]+", message="{devteam.User.emailAddress}")
Dick Solomon

You should put the file in the root, then

devteam.User.emailAddress[Pattern] = "Your message here"

notice [Pattern] to specify the message to output when the Pattern has a constraint violation. this makes it easier to maintain in my opinion vs having the messages like

@Patterh(regexp ="xx", message = "your message here")

for every setter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!