我有一个hibernate查询,它返回一个通知列表。
通知对象有一个Set
通知:
private BigDecimal id;
private BigDecimal createdBy;
private Date createDate;
private BigDecimal deletedBy;
private BigDecimal deletedDate;
private Set<Boards> notificationBoards = new HashSet<Boards>();
董事会:
private BigDecimal id;
private BigDecimal createdBy;
private Date createDate;
我的查询给了我一个
list of Notifications.
我必须根据板Id过滤通知。因此,我需要迭代板以检查Id。
例如,如果baords id=10,则我添加到新列表中,否则忽略。所以我想我会形成另一个新的通知列表,只有板id=10。
下面是我的循环
public List<Notifications> getNotificationList(List<Notifications> notification, Users loggedInUserObj){
List<Notifications> notificationLi = new ArrayList<Notifications>();
Set<Boards> boardLi = new HashSet<Boards>();
Boards b = new Boards();
Notifications n = new Notifications();
if(notification != null && notification.size() > 0){
for(Notifications notificationObj : notification){
n = notificationObj;
Set<Boards> notificationBoards = notificationObj.getNotificationBoards();
for(Boards board: notificationBoards){
if(board.getId() == loggedInUserObj.getBoardObj().getId()){
b = board;
}
boardLi.add(b);
}
n.setNotificationBoards(boardLi);
}
notificationLi.add(n);
}
return notificationLi;
}
我只收到了一个列表中的一个通知(根据数据,我预计会收到2个通知),并且公告板始终为空。有人能指出问题所在以及更好的解决方法吗?