728x90
// ajax 내용
var params = $(“#listForm”).serialize();
var paramsJson = JSON.parse(‘{“‘ + (params.replace(/&/g, “\”, \””).replace(/=/g, “\”:\””)) + ‘“}’);
for(var key in paramsJson){
paramsJson[key] = decodeURIComponent(paramsJson[key]);
}
var testId = “0001”;
var detailIdList = [];
for(var i=0; i<10; i++){
var $dtl = $(“input[name=dtl”+i+”]:checked”);
var $dtlDataId = $dtl.attr(“data-dtl”);
var $dtlVal = $dtl.val();
var dtlMap = new Map();
dtlMap.set(“dtlId”, $dtlDataId);
dtlMap.set(“testId”, testId);
dtlMap.set(“questionAnswer”, $dtlVal);
detailIdList.push(Object.fromEntries(dtlMap));
}
paramsJson[“detailIdList”] = detailIdList;
$.ajax({
type : “POST”,
async : false,
traditional : true,
contentType : “application/json”,
url : “<c:url value=“/test/modifyProc.do”/>’,
data : JSON.stringfy(paramsJson),
dataType : “json”,
success : function(data){
console.log(data);
},
error : function(xhr, ajaxSettings, thrownError){
console.log(“error——“);
}
});
// controller
@RequestMapping(value=“/test/modifyProc.do”, produces=“application.json; charset=UTF-8”)
@ResponseBody
@Transactional
public HashMap<String,String> modifyProc(HttpServletRequest req, ModelMap model
, @RequestBody TestVO paramsJson
) throws Exception{
String testId = paramsJson.getTestId();
List<testDetailVO> dtlList = paramsJson.getDtlList();
for(testDetailVO dtlVO : dtlList){
int updateDetailCnt = testService.updateTestDetail(dtlVO);
// 한 테스트에 대해서 문제별 점수를 업데이트 하는 과정.
}
int updateTestCnt = testService.updateTest(paramsJson);
HashMap<String, String> rtnMap = new HashMap<String, String>();
rtnMap.put(“updateTestCnt”, updateTestCnt);
rtnMap.put(“updateDetailCnt”, updateDetailCnt);
return rtnMap;
}
// VO
// 문제지 vo
public class TestVO{
String testId;
String score;
private List<testDetailVO> dtlList;
~~ getter ~ setter ~~
}
// 문제지 내의 문제별 vo
public class TestDetailVO{
String testId; // 문제지 id
String testDetailId; // 문제별 id
String questionAnswer; // 문제별 선택한 번호.
}
출처 ::
https://amy-it.tistory.com/112
https://leo-history.tistory.com/m/23
https://gent.tistory.com/295
https://gogo-jjm.tistory.com/m/6
https://developer0513.tistory.com/163
https://okky.kr/questions/953421
https://cloud.tencent.com/developer/ask/sof/100394660/answer/102564987
https://choiyeonho903.tistory.com/m/25
https://mingggu.tistory.com/m/66
728x90
'스프링' 카테고리의 다른 글
[Spring boot] jar 빌드 (0) | 2024.07.31 |
---|---|
[Spring Boot] 다국어 처리 (메세지 국제화) (0) | 2024.07.03 |
[Spring, jstl, JS] js에서 jstl 쓰기 (자바에서 a태그(onclick)를 만들어서 js를 써서 뿌리고 싶어요!) (0) | 2024.01.02 |
[ibatis] 프로시저 호출 (0) | 2023.12.13 |
[Spring] ibatis 에서 insert all 할 때 (1) | 2023.12.08 |