ssm學習筆記——數組類型與List類型綁定
阿新 • • 發佈:2018-11-02
detail [] req clas orm 綁定 cti hide ucc
一:數組類型
1.實現
1)前端
<form action="${pageContext.request.contextPath }/getlist.action" method="post"> 查詢條件: <table width="100%" border=1> <tr> <td><input type="submit" value="查詢"/></td> </tr> </table> 商品列表: <table width="100%"View Codeborder=1> <tr> <td>商品名稱</td> <td>商品價格</td> <td>生產日期</td> <td>商品描述</td> <td>操作</td> </tr> <c:forEach items="${itemList }" var="item" > <tr> <td><inputtype="checkbox" name="ids" value="${item.id}">${item.name }</td> <td>${item.price }</td> <td><fmt:formatDate value="${item.createtime}" pattern="yyyy-MM-dd HH:mm:ss"/></td> <td>${item.detail }</td> <td><ahref="${pageContext.request.contextPath }/itemEdit.action?id=${item.id}">修改</a></td> </tr> </c:forEach> </table> <input type="submit" value="查詢"/> </form>
2)Controller層
@RequestMapping(value = "/ids.action")
public ModelAndView getids(Integer[] ids) {
for (int i : ids) {
System.out.println(i);
}
System.out.println("o");
ModelAndView mav = new ModelAndView();
mav.setViewName("success");
return mav;
}
View Code
二:List實現
1.實現
1)前端
<form action="${pageContext.request.contextPath }/getlist.action" method="post"> 查詢條件: <table width="100%" border=1> <tr> <td><input type="submit" value="查詢"/></td> </tr> </table> 商品列表: <table width="100%" border=1> <tr> <td>商品名稱</td> <td>商品價格</td> <td>生產日期</td> <td>商品描述</td> <td>操作</td> </tr> <c:forEach items="${itemList }" var="item" varStatus="s"> <tr> <td><input type="text" name="list[${s.index}].name" value="${item.name }"></td> <td><input type="text" name="list[${s.index}].price" value="${item.price }"></td> <td><fmt:formatDate value="${item.createtime}" pattern="yyyy-MM-dd HH:mm:ss"/></td> <td>${item.detail }</td> <td><a href="${pageContext.request.contextPath }/itemEdit.action?id=${item.id}">修改</a></td> </tr> </c:forEach> </table> <input type="submit" value="查詢"/> </form>View Code
2)Controller層
註意:使用List的時候Controller層的形參只能為包裝類
@RequestMapping(value = "/getlist.action")
public ModelAndView getList(QueryVo list) {
for (Items s : list.getList()) {
System.out.println(s);
}
ModelAndView mav = new ModelAndView();
mav.setViewName("success");
return mav;
}
View Code
ssm學習筆記——數組類型與List類型綁定