zoukankan      html  css  js  c++  java
  • springmvc 处理lsit类型的请求參数映射成实体属性

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


    这是html页面请求提交到server的表单代码,注意文本框的属性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);
    	}

  • 相关阅读:
    mysql字符生命周期
    mysql5.6特殊字符问题
    电信网关-天翼网关-GPON-HS8145C设置桥接路由拨号认证
    linux-shell脚本高并发对文本url批量下载
    Kettle7.1在window启动报错
    微软的在线文档存储OneDrive使用帮助
    centos6.5搭建redmine3.4
    mysql基础拓扑图
    线上应用故障排查之一:高CPU占用
    线上服务CPU100%问题快速定位实战
  • 原文地址:https://www.cnblogs.com/clnchanpin/p/7107351.html
Copyright © 2011-2022 走看看