springmvc 处理lsit类型的请求参数映射成实体属性

<table align="center"  cellspacing="10">
  				<tr>
  					<td>
  					          母码数目:<input type="text" name="uidCodeGenNumParamList[0].superCodeGenNum"  style="width:180px;" class="textbox" maxlength="24"/>
  					        
  					        子码数目:<input type="text" name="uidCodeGenNumParamList[0].childCodeGenNum" style="width:180px;" class="textbox" maxlength="24" /> 					    
  					</td>
  				</tr>
 				<tr>
  					<td>
  					          母码数目:<input type="text" name="uidCodeGenNumParamList[1].superCodeGenNum"  style="width:180px;" class="textbox" maxlength="24"/>
  					        
  					        子码数目:<input type="text" name="uidCodeGenNumParamList[1].childCodeGenNum" style="width:180px;" class="textbox" maxlength="24" /> 					    
  					</td>
  				</tr>		
  			</table>


这是html页面请求提交到服务器的表单代码,注意文本框的属性name为:

name="uidCodeGenNumParamList[1].superCodeGenNum"


这是在服务端定义的实体:

public class UidCodeGenNumParam extends EntityBase {

	private String superCodeGenNum;
	private String childCodeGenNum;

	public String getSuperCodeGenNum() {
		return superCodeGenNum;
	}

	public void setSuperCodeGenNum(String superCodeGenNum) {
		this.superCodeGenNum = superCodeGenNum;
	}

	public String getChildCodeGenNum() {
		return childCodeGenNum;
	}

	public void setChildCodeGenNum(String childCodeGenNum) {
		this.childCodeGenNum = childCodeGenNum;
	}

}
必须要将这个类型作为list类型的属性包装在 bean 中:
public class UidCodeGenNumParamFormList extends EntityBase {

	private List<UidCodeGenNumParam> uidCodeGenNumParamList;

	public List<UidCodeGenNumParam> getUidCodeGenNumParamList() {
		return uidCodeGenNumParamList;
	}

	public void setUidCodeGenNumParamList(
			List<UidCodeGenNumParam> uidCodeGenNumParamList) {
		this.uidCodeGenNumParamList = uidCodeGenNumParamList;
	}



}

在controller中,获取list参数:

@RequestMapping(value="/add")
	public Object addUidCode(@ModelAttribute UidCodeGenNumParamFormList genNumList,
			HttpServletRequest req,HttpServletResponse resp) throws Exception{
		for(UidCodeGenNumParam genNum:genNumList.getUidCodeGenNumParamList()){
			System.out.println(genNum.getSuperCodeGenNum()+";"+genNum.getChildCodeGenNum());
		}
		Map<String,Object> busResult  = uidCodeBusiness.add(req,genNumList);	  
	    return CommonUtils.controlResult(busResult, resp);
	}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值