我有模型與對象參數。如何發送列表<model>通過添加其參數作爲對象
如果有3個不同的候選人,它應該顯示3個候選人,但我的輸出是重複最後一個候選人的細節3次。我沒有獲得前兩個候選人的詳細信息。
public class CandidateFeedbackDisplay implements Serializable{
private Candidate candidate;
private List<Integer> feedbackIds;
//setter and getters
}
public List<CandidateFeedbackDisplay> list(Integer cID, Integer jID, String accepted) throws Exception {
Session session = this.sessionFactory.getCurrentSession();
List<Candidate> candidateList = null;
CandidateFeedbackDisplay feedbackDisplay = new CandidateFeedbackDisplay();
List<CandidateFeedbackDisplay> feedbackDisplayList = new ArrayList();
// List<CandidateFeedbackDisplay> feedbackDisplayListTest = null;
try {
Query query = session.createQuery("from Candidate WHERE phoneNumber IN (select DISTINCT mobileNo from InviteCandidates WHERE c_id= :cID AND j_id= :jID AND status= :accepted)");
query.setInteger("cID", cID);
query.setInteger("jID", jID);
query.setString("accepted", accepted);
candidateList = query.list();
Iterator itr = candidateList.iterator();
while(itr.hasNext()){
Candidate candidate = (Candidate) itr.next();
System.out.println("candidate.getCandidateID() : " + candidate.getCandidateID());
List<CandidateFeedback> candidateFeedback = this.getFeedback(cID, jID, candidate.getCandidateID());
Iterator itr1 = candidateFeedback.iterator();
List<Integer> feedbackid = new ArrayList<Integer>();
while(itr1.hasNext()){
CandidateFeedback Feedback = (CandidateFeedback) itr1.next();
feedbackid.add(Feedback.getFeedbackID());
}
feedbackDisplay.setFeedbackIds(feedbackid);
feedbackDisplay.setCandidate(candidate);
feedbackDisplayList.add(feedbackDisplay);
// feedbackDisplayListTest.add(feedbackDisplay); // null pointer access error
}
}catch (Exception e) {
e.printStackTrace();
this.logger.error("Error while fetching List :" + e);
return null;
}
return feedbackDisplayList;
}
首先,你需要解釋一下你的代碼(認沽評論),並指出確切的代碼,你有問題,並且還去掉不必要的代碼 – Ravi
感謝您的快速回復 – Priya