繁体   English   中英

Spring - 多个验证注释的相同自定义消息

[英]Spring - same custom message for multiple validation annotations

是否可以在 Spring 4+ 框架中对多个注释使用相同的自定义消息。

就我而言,我想为 @NotNull 和 @NotEmpty 注释显示相同的消息。

@NotEmpty(message = "First name cannot be empty.")
@NotNull(message = "First name cannot be empty.")

是的,这是可能的。 消息在系统中不用作标识符,因此是可能的。 我建议使用ValidationMessages.properties

@NotEmpty(message = "{first.notnullorempty}")
@NotNull(message = "{first.notnullorempty}")

请参阅: https : //stackoverflow.com/a/4811273/5585182以防止一遍又一遍地复制粘贴相同的消息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM