spring boot 中Thymeleaf的迭代使用:
controller中:
@RequestMapping(value = "/findProduct")
public String findProduct(Map map){
List<Product> productList=productService.findAll();
map.put("productList",productList);
return "product";
}
application.yml中:
freemarker:
request-context-attribute: request
charset: UTF-8
cache: false
allow-request-override: false
check-template-location: true
content-type: text/html
expose-request-attributes: false
expose-session-attributes: false
expose-spring-macro-helpers: false
html中:
<tr th:each="pro:${productList}">
<td><input name="name" th:value="${pro.name}"/></td>
<td><input name="price" th:value="${pro.price}"/></td>
<td><input name="standerd" th:valu="${pro.standerd}"/></td>
<td><input name="code" th:value="${pro.code}"/></td>
<td><input name="srcPath" th:value="${pro.srcPath}"/>
</tr>