우선 json을 만드는 방법입니다.
{"mainList":[{"name":"john1","userId":"john11"},{"name":"john2","userId":"john22"}]}
예)
var totData = new Object();
var data = new Object();
var dataList = new Array();
data["name"] = "john1";
data["userId"] = "john11";
dataList.push(data);
var data = new Object();
data["name"] = "john2";
data["userId"] = "john22";
dataList.push(data);
totData["mainList"] = dataList;
console.log(totData);
이런식으로 만들어서
ajax 호출로 던짐 꼭 json 형식이 아니여도 form serialize 방식으로 던져도 되구요
$.ajax({
contentType:'application/json',
dataType : 'json',
data : JSON.stringify(totData),
url : 'test.json',
type : 'POST',
success:function(data){
}
});
constroll 단에서 받기
@RequestMapping(value = "/test.json", method=RequestMethod.POST)
@ResponseBody
public Result test(Result result, @RequestBody testVO param) throws Exception {
for(testVO str : param.getMainList()) {
System.out.println("name-------------->"+str.getName());
System.out.println("userId-------------->"+str.getUserId());
}
}
VO 단
public class testVO {
private String name;
private String userId;
private List<testVO> mainList;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public List<testVO> getMainList() {
return mainList;
}
public void setMainList(List<Wms151002VO> mainList) {
this.mainList = mainList;
}
}
혹시 dhtmlx 를 쓰시는 분은(제가 지금 dhtmlx플젝이라...)
var mainDataList = new Array();
var totData = new Object();
mainGrid.forEachRow(function(id){
var data = new Object();
mainGrid.forEachCell(id, function(cellObj,ind){
var columnName = mainGrid.getColumnId(ind);
var columnValue = mainGrid.cells(id,ind).getValue();
data[columnName] = columnValue;
});
mainDataList.push(data);
});
totData["mainList"] = mainDataList;
console.log(JSON.stringify(totData));
요런 식으로??ㅎㅎㅎㅎㅎㅎ