我正在使用Spring MVC 3,NetBeans
我有以下型号,
public class MarketPlace {
private String status;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
private String category;
public String getCategory() {
return category;
}
这是我的控制器方法,
@RequestMapping(value = "/ListApplication.htm", method = RequestMethod.GET)
public ModelAndView ShowForm(HttpServletRequest request) {
ModelAndView mav = new ModelAndView("ListApplication");
mav.addObject("apps", marketPlaceService.listApplications());
return mav;
}
marketPlaceService.listApplications()方法返回List。 这是我的观点,
<c:forEach items="${apps}" var="item">
<p>Template Name: ${item.templateName}</p>
<p>Description: ${item.description}</p>
<p>Category: ${item.category}</p>
<p><img " src="${item.templateLogo}" border="0" alt="" /></div></td></p>
<br><br>
</c:forEach>
从调试中我看到列表中至少有20条记录,但jsp视图没有显示任何内容。
修改: 有趣的是,这段代码正在运行,
protected ModelAndView handleRequestInternal(
HttpServletRequest request,
HttpServletResponse response) throws Exception {
ModelAndView mav = new ModelAndView("ListApplication");
mav.addObject("apps", marketPlaceService.listApplications());
return mav;
}
任何人都可以告诉我原因。
答案 0 :(得分:2)
您的<img>
标记格式不正确:
<img " src="${item.templateLogo}" border="0" alt="" />
应该是:
<img src="${item.templateLogo}" border="0" alt="" />
</div></td>
标记之后的<img/>
也不应该存在。
不确定模板名称,描述和类别......可能<img>
标签中的拼写错误导致jstl无法正确过滤。
答案 1 :(得分:2)
这是我发现的答案很快,
@RequestMapping(value = "/ListApplication.htm", method = RequestMethod.GET)
public String ShowForm(HttpServletRequest request, ModelMap m) {
m.addObject("apps", marketPlaceService.listApplications());
return "ListApplication";
}
欢迎进一步改进。但是,addObject似乎已被弃用,任何替代方案?