不知道如何迭代提供的“项目”在中这就是错误。我不知道如何在jsp中获取行?
当我点击我的网址时,我收到一个异常,它说不知道如何迭代
http://localhost:8081/Spring_hibernate/search?keyword=core
这是dao部分
public Offer getSearchByName(String companyName) {
Session session = sessionFactory.openSession();
Query<Offer> query = session.createNamedQuery("findBy.app", Offer.class);
query.setParameter("offerDetails", companyName);
Offer offerResult = query.getSingleResult();
return offerResult;
}
这是控制器
@RequestMapping("/search") 公共字符串搜索(@RequestParam(“关键字”)字符串offerDetails,模型模型){ 报价offer = OfferDaoImpl.getSearchByName(offerDetails); System.out.println("来自搜索方法"+offer.toString()); model.addAttribute("searchObject", 提供); 返回“搜索”; }
这是jsp页面
<c:forEach var="temp" items="${searchObject}">
<tr>
<td>${temp.id}</td>
<td>${temp.companayName}</td>
<td>${temp.offerDetails}</td>
<td>${temp.price}</td>
<td><a href="/Spring_hibernate/deleteOffer?offerId=${temp.id}">Delete</a></td>
<td><a href="/Spring_hibernate/updateOffer?offerId=${temp.id}">Update</a></td>
</tr>
</c:forEach>
when i hit my url i getting an exception it is saying Don't know how to iterate over supplied "items" in <forEach>
http://localhost:8081/Spring_hibernate/search?keyword=core
this is dao part
public Offer getSearchByName(String companyName) {
Session session = sessionFactory.openSession();
Query<Offer> query = session.createNamedQuery("findBy.app", Offer.class);
query.setParameter("offerDetails", companyName);
Offer offerResult = query.getSingleResult();
return offerResult;
}
this is the controller
@RequestMapping("/search") public String search(@RequestParam("keyword") String offerDetails , Model model) { Offer offer = offerDaoImpl.getSearchByName(offerDetails); System.out.println("from search method "+offer.toString()); model.addAttribute("searchObject", offer); return "search"; }
this the jsp page
<c:forEach var="temp" items="${searchObject}">
<tr>
<td>${temp.id}</td>
<td>${temp.companayName}</td>
<td>${temp.offerDetails}</td>
<td>${temp.price}</td>
<td><a href="/Spring_hibernate/deleteOffer?offerId=${temp.id}">Delete</a></td>
<td><a href="/Spring_hibernate/updateOffer?offerId=${temp.id}">Update</a></td>
</tr>
</c:forEach>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只能迭代有效的对象数组,例如 Collection、Map、Iterator、Enumeration 或 String。任何其他内容都不能通过进行迭代。
You can only iterate valid Object array such as Collection, Map, Iterator, Enumeration or String. Anything else can't be iterated by <c:forEach>.
您想要显示一个列表。将查询结果获取到集合中,并在“searchObject”中设置该集合。
如果查询结果不是集合,则删除 forEach 迭代器并简单地访问字段 (searchObject.price)。
You want to show a list. Get your query result in a collection, set that collection in "searchObject".
If the query result is not a collection, then remove forEach iterator and simply access the fields (searchObject.price).