【发布时间】:2019-05-11 17:52:12
【问题描述】:
我在注册页面的 JSF 的 Java bean 类上使用了 @NotNull 注释。但它没有按预期工作。
这是我的 xhtml 页面部分:
User Name : <h:inputText value="#{user.userName}" />
这是我的 Java bean 部分:
@NotNull(message = "User name cannot be null")
private String userName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
但它仍然将用户名保存到数据库(PostgreSQL)为''。所以从技术上讲,它不是空的。 我知道可能我还必须使数据库上的该列不为空。但是我们使用@NotNull 注解有什么用呢?
【问题讨论】:
标签: jsf bean-validation