我正在使用 Java 7 和 GlassFish 4.1.1 创建一个 Java EE Web 项目。我的 IDE 是 NetBeans。
从存储库类重构一些代码时,我将字符串“USERS”替换为模型类上的静态最终字段。立即执行此操作(清理并构建)后,我的服务中出现了 IllegalArgumentException,并发现该字段被读取为 null。
模型类:
public class User {
public static final String TABLE_NAME = "USERS";
public static final String PRIMARY_KEY = "ID";
private String id;
private String name;
public User(String id, String name) {
this.id = id;
this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
用户存储库,之前:
public List<User> get() throws RepositoryException
{
try {
return service.retrieve("USERS");
} catch (SQLException ex) {
throw new RepositoryException("Retrieval failed.", ex);
}
}
Run Code Online (Sandbox Code Playgroud)
用户存储库,之后: …