[spring] JSON 타입 데이터 리턴 받기
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value=”period/execPeriodProcedure”, method=RequestMethod.POST)
public JsonResponseVO execProcedure(HttpServletRequest request, HttpSession session, @RequestParam Map<String, Object> params){
JsonResponseVO updateResponse = new JsonResponseVO();
try {
updateResponse.setResponseCd(ComnCode.PROCESS_SUCCESS);
updateResponse.setResponseMsg(ComnConstants.PROCESS_SUCCESS);
} catch (Exception e) {
updateResponse.setResponseCd(ComnCode.PROCESS_ERROR);
updateResponse.setResponseMsg(ComnConstants.UPDATE_ERROR);
logger.error(“updateAccount() e = ” + e);
}
return updateResponse;
}
/**
* 공통코드 정의 클래스
* @author PJS
* @date 2014. 1. 7.
*/
public class ComnCode {
//정상처리
public static final String PROCESS_SUCCESS = “N0001”;
//정상예외
public static final String PROCESS_EXCEPTIION = “N0002”;
//실패
public static final String PROCESS_ERROR = “E0001”;
}
public class JsonResponseVO {
private String responseCd;
private String responseMsg;
private Map<String, Object> responseMap;
public String getResponseCd() {
return responseCd;
}
public void setResponseCd(String responseCd) {
this.responseCd = responseCd;
}
public String getResponseMsg() {
return responseMsg;
}
public void setResponseMsg(String responseMsg) {
this.responseMsg = responseMsg;
}
public Map<String, Object> getResponseMap() {
return responseMap;
}
public void setResponseMap(Map<String, Object> responseMap) {
this.responseMap = responseMap;
}
}
function execProcedure() {
if( !confirm(“진행하시겠습니까?”) ) {
return true;
}
$.ajax({
type: “POST”,
url: “execProcedure.do” />”,
data: $(‘#searchListForm’).serialize(),
dataType: “json”,
async: true,
success: function(data){
alert(data.responseMsg);
},
beforeSend: function(){
},
error: function(jqXHR, textStatus, errorThrown){
},
complete: function(){
}
});
}