我無法工作了,爲什麼我的foundUser對象回來爲空時,正確的參數被傳遞到findByUserName方法玩!框架,創建的對象甚至傳遞正確的值到方法
這裏就是方法後爲空稱爲
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;
}
據就行用戶foundUser = User.findByUserName(connection.connectionUserName)未;
我想要做的是從用戶的數據庫中獲取userName的詳細信息,該用戶的用戶名存儲在connection.ConnectionUserName變量中,但foundUser變量爲null,即使在調試中可以看到正確的字符串正在傳遞該方法
這裏是User類的findByUserName方法
public static User findByUserName(String userName) {
return find.where().eq("username", userName).findUnique();
}
任何幫助,將不勝感激,我想我只需要一組不同的眼睛看在這一點,並看到一個明顯的錯誤,我錯過了!
在此先感謝!
您是否驗證過'connection.connectionUserName'已填充? – StormeHawke
另外,你甚至使用'foundUser'作爲什麼?我沒有看到它聲明後的任何引用 – StormeHawke
@StormeHawke'connection.connectionUserName'填充了一個用戶名,'foundUser'被引用在下面的行中,'foundUser.jobTitle'我試圖獲得值for'jobTitle' – adamtrousdale