【发布时间】:2014-02-12 22:27:04
【问题描述】:
当正确的参数被传递给 findByUserName 方法时,我无法弄清楚为什么我的 foundUser 对象返回为 null
这里是调用方法的地方
public static ObjectNode getAllConnections(String userName){
List<Connections> connectionsUsernames = find.where().eq("username", userName).findList();
Iterator<Connections> connectionsIterator = connectionsUsernames.iterator();
ObjectNode response = Json.newObject();
ObjectNode responseItem = Json.newObject();
while (connectionsIterator.hasNext()){
Connections connection = connectionsIterator.next();
User foundUser = User.findByUserName(connection.connectionUserName);
responseItem.put("jobtitle", foundUser.jobTitle);
responseItem.put("connectionid", connection.connectionId.toString());
responseItem.put("connectionusername", connection.connectionUserName);
responseItem.put("connectiondate", connection.connectionDate);
response.put(connection.connectionUserName, responseItem);
}
return response;
}
在 User foundUser = User.findByUserName(connection.connectionUserName); 这条线上失败了
我要做的是从用户的数据库中获取用户的详细信息,该用户的用户名存储在 connection.ConnectionUserName 变量中,但 foundUser 变量为空,即使我可以在调试中看到正确的字符串正在传递给方法
这里是 User 类中的 findByUserName 方法
public static User findByUserName(String userName) {
return find.where().eq("username", userName).findUnique();
}
任何帮助都将不胜感激,我想我只需要一双不同的眼睛来查看这个并看到我遗漏的明显错误!
提前致谢!!
【问题讨论】:
-
您是否验证了
connection.connectionUserName已填充? -
另外,你还用
foundUser做什么?声明后我没有看到对它的任何引用 -
@StormeHawke
connection.connectionUserName填充了用户名,foundUser在下面的行中引用,foundUser.jobTitle我试图在其中获取jobTitle的值 -
抱歉,我错过了那行。
-
@StormeHawke 有什么想法吗?
标签: java playframework playframework-2.0