// rows相当于java中的集合
var rows = $('#tt').datagrid('getSelections');//easyui,datagrid方法返回多行
var testModel={};//定义一个对象
testModel.patients=rows;//把这集合放进去
//自定义一个对象patient也放进去
testModel.patient={
"name" : "xxx",
"age": 11,
"sex" : 1
};
$.ajax({
type: "POST",
url: "/patientController/test/adds",
data: JSON.stringify(testModel), // 这样传递到后台
contentType: "application/json;charset=UTF-8", // 必须
success: function( result ) {
console.log(result )
}
});
// 后端java 接收
// 首先建一个与之对应的类
package com.elven.member.model;
import java.util.ArrayList;
import com.elven.member.pojo.Patient;
public class TestModel {
private ArrayList<Patient> patients;
private Patient patient;
public ArrayList<Patient> getPatients() {
return patients;
}
public void setPatients(ArrayList<Patient> patients) {
this.patients = patients;
}
public Patient getPatient() {
return patient;
}
public void setPatient(Patient patient) {
this.patient = patient;
}
}
//controller
/**
* 测试接收数组
* 对象
* */
@RequestMapping("/test/adds")
@ResponseBody
public String testAdds(@RequestBody TestModel testModel) {
ArrayList<Patient> patients = testModel.getPatients();
System.out.println("patient---------"+testModel.getPatient());
for (Patient patient : patients) {
System.out.println(patient);
}
String str = "成功!";
return str;
}
参考博客,论坛