传参和获取参数值的方法

4 篇文章 0 订阅

           项目中jsp页面要给action传递参数值,这里总结了我用到的方法分享给大家。

一、方法(一)

1.功能

       批量审核时选中商品种类,然后把id传入。

 

2.jsp传参

 /**批量审核**/
		 function verifyAll(){
		 	var id = new Array();
		 	var chklist=document.getElementsByName("chk_list");
		 	 for (var i=0;i<chklist.length;i++) {
				  var e=chklist[i];
				  if (e.checked) {
					id.push(e.value);
				}
			 }
			 if(id.length==0){
				alert("请先选中一条记录!");
				return false;
			}
			 if(confirm("确定要审核吗?")){
	               	window.location.href="${pageContext.request.contextPath}/entrance_All.action?idArry=" + id;
	        		
		    }
		    return false;
		 }


3.action获取参数

  用request方法获得参数

/**
	 * 批量审核入场信息   张晓
	 * @return
	 * @throws Exception
	 */
	public String All() throws Exception {
		String idStr = ServletActionContext.getRequest().getParameter("idArry");
		String[] idArry = idStr.split(",");
		for (String iditem : idArry) {
			if (StringUtils.isNotBlank(iditem)) {
//				marketService.update(Market.class, "o.state=?1", "where o.marketId=?2",);
				int itemid =Integer.parseInt(iditem);
				entranceService.update(Entrance.class, new Object[]{"verifyState","verifyResult"}, new Object[]{"entranceId"}, new Object[]{Constants.VRY,Constants.VRY,itemid});
			}
		}
				
		return "toListOfMarket";
	}


二、方法(二)

1.功能

   点击注销按钮,把商户id传入,注销商户就是更改商户状态和摊位状态


2.jsp传参

<td style="text-align:center">
	<s:if test="tenantStatus == '已加入'">
		<a title="注销" href="tenant_exit.action?tenantId=${tenantId}" οnclick="return confirm('确定要注销吗?') ">注销</a>
	</s:if>
	<s:elseif test="tenantStatus == '注销'">
	</s:elseif>
</td>


3.action获取参数

  因为商户id是在model中的,所以action中用model.getTenantId()即可获得参数

/**
	 * 商户注销页面  张晓
	 * 注销
	 * @return
	 * @throws Exception
	 */
	public String exit() throws Exception {
		Tenant tenant = tenantService.getById(Tenant.class, model.getTenantId());
		int outNumber =  tenant.getOutNumber() + 1;
		//1.商户注销更改状态
		System.out.println("退出次数==" + outNumber);
		tenantService.update(Tenant.class,new Object[]{"tenantStatus","outNumber"}, new Object[]{"tenantId"}, new Object[]{Constants.tenantExit,outNumber,model.getTenantId()});
		//2.摊位状态改为不使用
			//2.1.取出摊位
			LinkedHashMap<Object, Object> equalFields = new LinkedHashMap<Object, Object>();
			equalFields.put("tenant", tenant);
			List<Booth> boothList = boothService.findResultListByEqual(Booth.class, equalFields);
			ArrayList boothnumArray = new ArrayList();
			//2.2将摊位号字段放入list中,并将状态改为不使用
			for(int i = 0;i<boothList.size();i++){
				int bid = boothList.get(i).getId();
				String boothnum = boothList.get(i).getBoothNumber();
				boothnumArray.add(boothnum);
				System.out.println(bid);
				System.out.println(boothnumArray);
				boothService.update(Booth.class, "o.state=?", "where o.id=?", new Object[]{Constants.boothN,bid} );
			}
			
		return "exit";
	}


三、总结

       记是记不住的。总结到这里用到的时候过来看看。如果还有别的好方法大家及时分享哈!


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值