主要是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;
}
}