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);
}