【发布时间】:2013-11-18 18:31:29
【问题描述】:
我不明白问题出在哪里,显示数据。他有标题(名称、价格和数量),但没有数据
这里是控制器
@Controller
public class ProductListController {
@Autowired ProductRepository productRepository;
@RequestMapping("/productlist")
public ModelAndView showProductList() {
ModelAndView mv = new ModelAndView("productlist");
List<Product> list = productRepository.findAll();
mv.addObject("displayProduct",list);
return mv;
}
}
这是productlist.jsp
<!DOCTYPE html >
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c' %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<html>
<head>
<title>Product</title>
</head>
<body>
<form:form method="POST" modelAttribute="displayProduct">
<table border="1" >
<tr>
<td>Name</td>
<td>Price</td>
<td>Quantity</td>
</tr>
<c:forEach items="${displayProduct}" var="p">
<c:out value="${p.name}"/>
</c:forEach>
</table>
</body>
</html>
【问题讨论】:
-
向我们展示您的
Product课程。
标签: jsp spring-mvc