728x90
반응형
let formdata = new FormData();
formdata.enctype='multipart/form-data';
formdata.method='post';
formdata.append('data',JSON.stringify(this.bookList));
formdata.append('deleteCount',this.deleteCount);
const xhr = new XMLHttpRequest();
xhr.open("post", "/draw/data/updateInfoBookData.do", true);
xhr.onreadystatechange = function() { //폴백
if (xhr.readyState == 4) {
if (xhr.status == 200) { //200은 잘넘어왔단 것이다.
//callback(JSON.parse(xhr.response),text);
} else {
alert("요청오류 : " + xhr.status);
}
}
}
//post방식은 xhr객체에 데이터를 붙여서 전송
xhr.send(formdata);
this.bookList는
json array 형태로 되어있다.
[{"a":b ,"c":d} , {"a":b ,"c":d} ,{"a":b ,"c":d} ,{"a":b ,"c":d}]
Controller
String jsonParam = request.getParameter("data").replaceAll(""", "\"");
JSONParser jsonParse = new JSONParser(); //JSONParse에 json데이터를 넣어 파싱한 다음 JSONObject로 변환한다.
Object jsonObj = jsonParse.parse(jsonParam);
org.json.simple.JSONArray jsonArray = (org.json.simple.JSONArray)jsonObj;
json data를 받으면 replace를 통해 json 형태로 해석해주고
simple jsonArray를 통해 jsonArray 형태로 변경해준다.
JSon array 를
List<Map<String,Object>> info = (ArrayList<Map<String,Object>>)jsonArray;
형태로 변경후
HashMap<String, Object> bookHashMap = new HashMap();
for(int i=0;i<paramMap.size();i++) {
bookHashMap = new Gson().fromJson(paramMap.get(i).toString(), HashMap.class);
bookHashMap.put("newPageNum", i+1);
list형식을 for문을 돌린뒤
Gson을 통해 hashMap으로 형변화 시켜준다.
728x90
반응형
'Spring' 카테고리의 다른 글
Spring boot[maven] - profile에 따른 application.yml 파일 설정 및 암호화 (0) | 2022.02.04 |
---|---|
canvas blob을 spring에서 받아 mybatis를 통해 mysql db저장 및 출력 (0) | 2021.05.13 |
[스프링(Spring)] 스프링이란 무엇인가!? -1 (0) | 2021.02.19 |
POJO란 도대체 무엇인가? (0) | 2020.04.22 |
Springframework <form:form> 이란? (0) | 2020.04.20 |
댓글