方法1:
var rowData=$("#grid").jqGrid("getRowData");
for(var i=0;i<rowData.length;i++){
delete rowData[i].operate;
}
var postData={
customer:"customer",
data:JSON.stringify(rowData)
};
Public.ajaxPost("ajaxtest.do
",postData,function(data){
alert(data);
});
}
@ResponseBody
@RequestMapping(value="ajaxtest.do
")
public String ajaxTest(String customer,String data) throws JsonMappingException, IOException{
System.out.println(customer);
String listStr=java.net
.URLDecoder.decode(data, "UTF-8");
ObjectMapper mapper = new ObjectMapper();
JavaType javaType = mapper.getTypeFactory().constructCollectionType(ArrayList.class, Gy_Settlement.class);
List<Gy_Settlement> list=(List<Gy_Settlement>)mapper.readValue(listStr, javaType);
for(Gy_Settlement s:list) {
System.out.println(s.toString());
}
return null;
}
function ajaxtest(){
var rowData=$("#grid").jqGrid("getRowData");
for(var i=0;i<rowData.length;i++){
delete rowData[i].operate;
}
var data={
customer:"customer",
items:rowData
}
var postData={
data:JSON.stringify(data)
};
Public.ajaxPost("ajaxtest.do",postData,function(data){
alert(data);
});
}
后台:
@ResponseBody
@RequestMapping(value="ajaxtest.do")
public String ajaxTest(String data) throws JsonMappingException, IOException{
ObjectMapper om=new ObjectMapper();
Map<String,Object> map=om.readValue(data, Map.class);
System.out.println(map.get("customer"));
System.out.println("items"+map.get("items"));
JavaType javaType = om.getTypeFactory().constructCollectionType(ArrayList.class, Gy_Settlement.class);
List<Gy_Settlement> list=(List<Gy_Settlement>)om.readValue(om.writeValueAsBytes(map.get("items")), javaType);
for(int i=0;i<list.size();i++) {
System.out.println(list.get(i).toString());
}
for(Gy_Settlement s:list) {
System.out.println(s.toString());
}
System.out.println(list.size());
return null;
}
。。目前太菜了,能用就行了,有更好的方法请指教分享。。