zoukankan      html  css  js  c++  java
  • 在不是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', 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', 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);
    		}
    	}
    
  • 相关阅读:
    py-day1-2 python的循环语句
    B/S和C/S结构的区别
    php get_magic_quotes_gpc() addslashes()
    SqlHelper数据库访问类
    随滚动条滚动的居中div
    有关Repeater的事件
    Repeater的ItemCommand事件和ItemCreated事件,高手请跳过~
    温故而知新之数据库的分离和附加…高手请跳过….
    自己做的一个小功能~
    php什么是变量的数据类型
  • 原文地址:https://www.cnblogs.com/kyxyes/p/3517116.html
Copyright © 2011-2022 走看看