'Needing help sorting through a list in JAVA using Spring
New and learning Java, using Spring. Having some issues and just looking for a little direction. I am creating a social app. how can i sort my "deal" comments so i can only see those "deal" comments made for that specific "share"? Users can make a share and on that share page users can make deal(more comments for that share only) I have a list but that will show ALL the deals made, and that isn't what i want...
HOME CONTROLLER
@GetMapping("/{collectorId}/share/{id}")
public String LetMakeADeal(@PathVariable("id") Long shareId, @ModelAttribute("newDeal") Deal theDeal, Collector collector, Model model, HttpSession session, BindingResult result) {
Share share = shareService.getOneShare(shareId);
Collector collector1=collectorService.findCollectorById((Long) session.getAttribute("collectorId"));
List<Deal> deals = this.dealService.allDeals();
model.addAttribute("collector",collector1);
model.addAttribute("share", share);
model.addAttribute("collectorLoggedIn",(Long)session.getAttribute("collectorId"));
model.addAttribute("deals", deals);
session.setAttribute("collectorId", collector1.getId());
session.setAttribute("collector", collector1.getId());
return "dealwall.jsp";
}
MY DEALWALL.JSP PAGE
<c:forEach items="${deals}" var="deal">
<c:out value="${deal.collector.firstName }"/> Said: <c:out value="${deal.deal }"/><br>
<c:if test="${deal.collector.id==collectorLoggedIn}">
<br>
<a class="button button1" href="/deal/delete/${collector.id }/${deal.id }">Delete</a>
</c:if>
</c:forEach>
Solution 1:[1]
is delas have shareId ? then try this
model.addAttribute("deals", deals.stream().filter(t->t.getShareId() == shareId));
using java lambda filter
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | dangerousmanleesanghyeon |
