ajax+springmvc交互对象包含List集合的参数

5 篇文章 0 订阅
1 篇文章 0 订阅

主要是ajax对json包装的使用
核心代码如下:

jQuery.prototype.serializeObject=function(){  
    var obj=new Object();  
    $.each(this.serializeArray(),function(index,param){  
        if(!(param.name in obj)){  
            obj[param.name]=param.value;  
        }  
    });  
    return obj;  
}; 

前端页面js代码(这里就用到了开头写的serializeObject【序列化表单数据】方法):

function saveForm() {
	var json = $('#myForm').serializeObject();
	setListData(json);
	// 保存操作
	$.ajax({
		type : 'post',
		url : 'common/firstreport/saveFirstReport',
		data : json,  
		dataType : 'json',
		traditional : true,
		//contentType:'application/json', //注意这里不要加这个参数
		success : function(resData) {
			if (resData.code == 1) {
				showTimeoutMsg('操作成功',250,function(){
					refreshParentTable();
					closeThisTab();
				});
			}else{
				showTimeoutMsg('操作失败!',250,null);
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) { // 设置表单提交出错
			console.log(XMLHttpRequest.status);
               console.log(XMLHttpRequest.readyState);
               console.log(textStatus + "  ==>> " + errorThrown);
			showTimeoutMsg('操作失败,请联系系统管理员或稍后再试!',250,null);
		},
	});	
}

function setListData(json) {
	
	//获取备案机构股东信息
	getShareHolderList(json);
	//获取删除备案机构股东信息
	getDelShareHolderList(json);

	//获取诚信信息列表
 	getIntegrityInfoList(json);
	//获取删除诚信信息列表
	getDelIntegrityInfoList(json);
	
}

function getShareHolderList(param) {
	var arr = $("#beianjigougd").datagrid('getRows');
	if(arr && arr.length>0){
		$.each(arr, function(i, obj){
			// 拼接数组对象需要的格式,如:param['shareholderList[0].id']='abc'
			$.each(obj, function(key, val){
				if(!(key=='pager' || key=='createTime' || key=='updateTime')){
					param['shareholderList['+i+'].'+key] = val;
				}
			});
		});
	} 
}
	
function getDelShareHolderList(param) {
	var arr = delShareholderIds;
	if(arr != null && arr.length>0){
		// 拼接数组对象需要的格式,如:param['delShareholderList[0]']='abc'
		$.each(arr, function(i, val){
			param['delShareholderList['+i+']'] = val;
		});
	}

}
	
function getIntegrityInfoList(param) {
	var arr = $("#chengxin").datagrid('getRows');
	if(arr && arr.length>0){
		$.each(arr, function(i, obj){
			// 拼接数组对象需要的格式,如:param['integrityInfoList[0].id']='abc'
			$.each(obj, function(key, val){
				if(!(key=='pager' || key == 'createTime' || key=='updateTime')){
					param['integrityInfoList['+i+'].'+key] = val;
				}
			});
		});
	} 
}
	
function getDelIntegrityInfoList(param) {
	var arr = delChenxinIds;
	if(arr != null && arr.length>0){
		// 拼接数组对象需要的格式,如:param['delIntegrityInfoList[0]']='abc'
		$.each(arr, function(i, val){
			param['delIntegrityInfoList['+i+']'] = val;
		});
	}
}


Controller层:

@RequestMapping(value="/saveFirstReport",method=RequestMethod.POST)
@ResponseBody
public JSONObject saveFirstReport(HttpServletRequest request, CommonFirstFilingReport
	offcourtSecuritySRFirstFilingReport) {
	JsonResult result = null;
	try {
				
		filingReportService.doSave(offcourtSecuritySRFirstFilingReport, getTableFirstReport(request));
	
		//保存 备案机构股东信息
		List<CommonFirstFilingReportShareholder>  reportShareholders = 
			offcourtSecuritySRFirstFilingReport.getShareholderList();
		//已删除的 备案机构股东信息
		List<String> delShareholderList = offcourtSecuritySRFirstFilingReport.getDelShareholderList();
		firstFilingReportShareholderService.doSaveBatch(offcourtSecuritySRFirstFilingReport.getId(), 
			reportShareholders, delShareholderList, getTableShareholder(request));
			
		//保存 诚信信息
		List<CommonFirstFilingReportIntegrityInfo>  reportIntegrityInfos = 
			offcourtSecuritySRFirstFilingReport.getIntegrityInfoList();
		//已删除的 诚信信息
		List<String> delIntegrityInfoList = offcourtSecuritySRFirstFilingReport.getDelIntegrityInfoList();
		filingReportIntegrityInfoService.doSaveBatch(offcourtSecuritySRFirstFilingReport.getId(),
			reportIntegrityInfos, delIntegrityInfoList, getTableIntegrityInfo(request));
		
		result = new JsonResult(Response.SUCCESS);
	} catch (BaseException e) {
		e.printStackTrace();
		result = new JsonResult();
		result.getExceptionResult(e);
	}
	return result.getResult();
}

model层:

public class CommonFirstFilingReport{

	/**
	 * @对应的表字段:.id
	 */
	private String id;

	/**
     * 创建用户id
     */
    private String createUser;
    
    /**
     * 创建人的父用户id
     */
    private String createOrgUser;

	/**
	 * 场外证券业务名称@对应的表字段:.otc_securities_business
	 */
	private String otcSecuritiesBusiness;
	
	/**
	 * 诚信信息
	 */
	private List<CommonFirstFilingReportIntegrityInfo> integrityInfoList;
	/**
	 * 诚信信息删除数据
	 */
	private List<String> delIntegrityInfoList;
	
	/**
	 * 备案机构股东信息
	 */
	private List<CommonFirstFilingReportShareholder> shareholderList;
	/**
	 * 备案机构股东信息删除数据
	 */
	private List<String> delShareholderList;

	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getCreateUser() {
		return createUser;
	}

	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}

	public String getCreateOrgUser() {
		return createOrgUser;
	}

	public void setCreateOrgUser(String createOrgUser) {
		this.createOrgUser = createOrgUser;
	}

	/**
	 * 场外证券业务名称
	 * 
	 * @return otc_securities_business 场外证券业务名称
	 */
	public String getOtcSecuritiesBusiness() {
		return otcSecuritiesBusiness;
	}

	/**
	 * 场外证券业务名称
	 * 
	 * @param otcSecuritiesBusiness
	 *            场外证券业务名称
	 */
	public void setOtcSecuritiesBusiness(String otcSecuritiesBusiness) {
		this.otcSecuritiesBusiness = otcSecuritiesBusiness == null ? null : otcSecuritiesBusiness.trim();
	}

	public List<CommonFirstFilingReportIntegrityInfo> getIntegrityInfoList() {
		return integrityInfoList;
	}

	public void setIntegrityInfoList(List<CommonFirstFilingReportIntegrityInfo> integrityInfoList) {
		this.integrityInfoList = integrityInfoList;
	}

	public List<String> getDelIntegrityInfoList() {
		return delIntegrityInfoList;
	}

	public void setDelIntegrityInfoList(List<String> delIntegrityInfoList) {
		this.delIntegrityInfoList = delIntegrityInfoList;
	}

	public List<CommonFirstFilingReportShareholder> getShareholderList() {
		return shareholderList;
	}

	public void setShareholderList(List<CommonFirstFilingReportShareholder> shareholderList) {
		this.shareholderList = shareholderList;
	}

	public List<String> getDelShareholderList() {
		return delShareholderList;
	}

	public void setDelShareholderList(List<String> delShareholderList) {
		this.delShareholderList = delShareholderList;
	}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值