簡體   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