jqGrid獲取所有行數據提交保存

function saveFun(){
	debugger;
	Supp.alert("專家保存按鈕",Supp.alert.type.info);
	var rowSet = $("#jqGrid").jqGrid('getRowData');//獲取或有行數據  json數組的形式
	Supp.ajax({
		url:ExpertExtract.saveOrUpdate,
		type:"post",
		async:true,
		dataType:"json",
		data: {
			data :JSON.stringify(rowSet)//將json數組轉爲String字符串
		},
		success:function(resp){
			if(resp){
				Supp.showSuccess("保存成功!");
			}else{
				Supp.showSuccess("保存失敗!");
			}
			
		}
	});
	
	console.log(rowSet);
	
}

後端處理:

public OperResult<ExpertList> saveOrUpdate(HttpServletRequest request){
		String data = request.getParameter("data");
		JSONArray object = JSONArray.fromObject(data);//將String轉json數組
		//JSONArray.toArray(object, ExpertList.class);
		@SuppressWarnings({ "unchecked", "deprecation" })
		List<ExpertList> lists=(List<ExpertList>)JSONArray.toList(object, ExpertList.class);//將json集合jArray放入list集合中,
		for(ExpertList s : lists){
			service.saveOrUpdate(s);
		}
		return OperResult.succeed(null);
		
	}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章