在不是modelAttribute的情况下,如何保存页面输入值的方法(多行遍历)
<c:forEach var="prdRelInfo" items="${goodRelPrdList}" varStatus="s"> <tr <c:if test="${!(s.index%2==0) }"> class="tdbgcolor"</c:if>> <td><c:out value="${prdRelInfo.prdGoodId.goodsCode}"/></td> <td><c:out value="${prdRelInfo.prdGoodId.goodsName}"/></td> <td><c:out value="${prdRelInfo.prdGoodId.goodsBrand.name}"/></td> <td> <c:if test="${prdRelInfo.prdGoodId.skuType eq '1'}">正常产品</c:if> <c:if test="${prdRelInfo.prdGoodId.skuType eq '2'}">赠品</c:if> <c:if test="${prdRelInfo.prdGoodId.skuType eq '3'}">附件</c:if> <c:if test="${prdRelInfo.prdGoodId.skuType eq '4'}">虚拟产品</c:if> </td> <td><c:if test="${prdRelInfo.prdGoodId.hasStandPart != null and prdRelInfo.prdGoodId.hasStandPart == '1'}"><a onclick="artDialog({title:'普通商品',url:'goodsInfo.do?actionMethod=viewAccessory&opType=stand&queryId=${prdRelInfo.prdGoodId.id}&specialGoods=true', width:800, height:520,lock:true});" href="#">查看</a></c:if> <c:if test="${prdRelInfo.prdGoodId.hasStandPart == null or prdRelInfo.prdGoodId.hasStandPart == '2'}">无</c:if> </td> <td><c:if test="${prdRelInfo.prdGoodId.hasOptionPart != null and prdRelInfo.prdGoodId.hasOptionPart == '1'}"><a onclick="artDialog({title:'组合商品',url:'goodsInfo.do?actionMethod=viewAccessory&opType=optional&queryId=${prdRelInfo.prdGoodId.id}&specialGoods=true', width:800, height:520,lock:true});" href="#">查看</a></c:if> <c:if test="${prdRelInfo.prdGoodId.hasOptionPart == null or prdRelInfo.prdGoodId.hasOptionPart == '2'}">无</c:if> </td> <c:set var="isShowMain" value="false"/> <c:forEach var="goodRelPrd" items="${goodMainRelPrdList}"> <c:if test="${goodRelPrd.prdGoodId.id==prdRelInfo.prdGoodId.id}"> <c:set var="isShowMain" value="true"/> </c:if> </c:forEach> <td> <input type="radio" name="mainPrd" id="mainPrd_${prdRelInfo.prdGoodId.id}" onclick="<c:if test="${goodsInfo.id != null}">if(confirm('确认要设为主商品吗?')){assignAccessorySave('${prdRelInfo.prdGoodId.id}');}</c:if>"> </td> <c:if test="${goodsInfo.id != null}"> <c:if test="${isShowMain}"> <script language="javascript"> window.setTimeout("showHideButton('${prdRelInfo.prdGoodId.id}','${isShowMain}');",10); </script> </c:if> </c:if> <td> <input type="radio" name="assemble_propertyType_${prdRelInfo.prdGoodId.id}" id="assemble_propertyType_${prdRelInfo.prdGoodId.id}_1" value="1" <c:if test="${prdRelInfo.propertyType eq '1'}"> checked="checked"</c:if> onclick="<c:if test="${goodsInfo.id != null}">updatePropertyType(this,'${prdRelInfo.prdGoodId.id}','assemble','${isShowMain}');</c:if>"/>商品 <input type="radio" name="assemble_propertyType_${prdRelInfo.prdGoodId.id}" id="assemble_propertyType_${prdRelInfo.prdGoodId.id}_2" value="2" <c:if test="${prdRelInfo.propertyType eq '2'}"> checked="checked"</c:if> onclick="<c:if test="${goodsInfo.id != null}">updatePropertyType(this,'${prdRelInfo.prdGoodId.id}','assemble','${isShowMain}');</c:if>"/>赠品 </td> <td width="5%"><input type="text" name="num_${prdRelInfo.id}" value="${prdRelInfo.number}"/></td> <td><a href="#" onclick="if(confirm('确认要取消商品吗?')){deleteIt(this,'${goodsInfo.id}','${prdRelInfo.prdGoodId.id}');}">取消商品</a></td> </tr> </c:forEach>
其中 <td width="5%"><input type="text" name="num_${prdRelInfo.id}" value="${prdRelInfo.number}"/></td> 要将 值写道数据库中
在Controller类中,通过遍历取出多个值
List<PrdRelGoods> prdRelGoodsList2 = goodsInfoService .getGoodsRelPrd(goodsInfo.getId()); Iterator<PrdRelGoods> iterator=prdRelGoodsList2.iterator(); while(iterator.hasNext()) { PrdRelGoods prdRelGoods=iterator.next(); //System.out.println("prd_ref_goods_id---------------------->"+prdRelGoods.getId()); int num=Integer.valueOf(request.getParameter("num_"+prdRelGoods.getId())); prdRelGoods.setNumber(num); }
在service类中 通过hql语言 获取List
@SuppressWarnings("unchecked") public List<PrdRelGoods> getGoodsRelPrd(final Long goodsInfoId) { String sql = ""; if (goodsInfoId == null) { sql = "from PrdRelGoods t"; return hibernateTemplate.find(sql + " order by t.id asc"); } else { sql = "from PrdRelGoods t where t.goodsInfo.id=?"; return hibernateTemplate.find(sql + " order by t.id asc", goodsInfoId); } }
自信与努力 用心坚持