這裏是我的FormBean: -JSR 303 Bean驗證春季
public class LoginFormBean {
@NotEmpty
private String userId;
@NotEmpty
private String password;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getPassword() {
return password;
}
public void setPassword(String pass) {
this.password = pass;
}
}
,並在我的message.properties文件我寫: -
NotEmpty={0} must not empty.
它顯示了我的錯誤消息:userId must not empty.
和password must not empty.
但我想要顯示錯誤消息爲User Id must not empty.
或'Password must not empty.'
我知道我可以在我的formBean中使用@NotEmpty(message="User Id must not empty")
,但我想同步消息,就好像我們需要更改消息一樣,它的開銷會小一些。
我搜索了JSR文檔,但沒有找到任何東西來替換我的屬性名稱userId
到User Id
在飛行中。請大家幫助我,從兩天內就陷入困境。
如果這是不可能的,那麼告訴我,如果沒有,然後幫助我的東西替代。
感謝
沙姆斯
感謝您的回覆,是的,我知道我可以像這樣使用,但它仍然不是「可重複使用」。在這種情況下,我必須爲屬性文件中的每個屬性創建一個新條目,即使我在多個bean中使用'userId'屬性。 – Shams 2011-06-28 13:29:35