项目中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";
}
三、总结
记是记不住的。总结到这里用到的时候过来看看。如果还有别的好方法大家及时分享哈!