IT 소식

 

 

 
	
축구: 야구: 농구:
 
function goAjax6(){
	
	var checkValues = new Array();
	$("input[name='type']:checked").each(function(){
		checkValues.push($(this).val());
	});
	
	var data = {"userId": $("#userId").val(), "userPass":$("#userPass").val(), "type":checkValues }; 
	
 	$.ajax({
		type: "POST",
		url : "",
		data : JSON.stringify(data),
		dataType: "json",
		contentType:"application/json;charset=UTF-8",
		async: false,
		success : function(data, status, xhr) {
			console.log(data);
		},
		error: function(jqXHR, textStatus, errorThrown) {
			alert("error= " + errorThrown);
		}
	});
}
 

	/**
	 * @param JSON 데이터 받기
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/goAjax6.do", method = RequestMethod.POST)
	@ResponseBody
	public Map goAjax3(@RequestBody String param) throws Exception{
		
		JSONObject json = JSONObject.fromObject(param);
		System.out.println("userId:"+json.get("userId"));
		System.out.println("userPass:"+json.get("userPass"));
		System.out.println("type:"+json.get("type"));
		
		JSONArray array = (JSONArray) json.get("type");
		for(int i=0; i map = new HashMap();
		map.put("AA", "1");
		map.put("BB", "2");
		return map;
	}

'프로그래밍 > Spring' 카테고리의 다른 글

Ajax JSON Map 타입으로 넘기고 받기  (0) 2018.01.30
전자정부 프레임워크 Ajax 설정  (0) 2018.01.09
Spring properties 설정방법  (0) 2017.10.26


	
축구: 야구: 농구:
function goAjax5(){ var checkValues = new Array(); $("input[name='type']:checked").each(function(){ checkValues.push($(this).val()); }); var data = {}; data["userId"] = $("#userId").val(); data["userPass"] = $("#userPass").val(); data["type"] = checkValues; $.ajax({ type: "POST", url : "", data : JSON.stringify(data), dataType: "json", contentType:"application/json;charset=UTF-8", async: false, success : function(data, status, xhr) { console.log(data); }, error: function(jqXHR, textStatus, errorThrown) { alert("error= " + errorThrown); } }); } @RequestMapping(value = "/goAjax5.do", method = RequestMethod.POST) @ResponseBody public Map goAjax5(@RequestBody Map map) throws Exception{ System.out.println("userId:"+map.get("userId")); System.out.println("userPass:"+map.get("userPass")); System.out.println("type:"+map.get("type")); Map resultMap = new HashMap(); map.put("AA", "1"); return resultMap; } ##출력값 userId:test1234 userPass:pass1234 type:[축구, 야구, 농구]

'프로그래밍 > Spring' 카테고리의 다른 글

Ajax JSON 데이터 주고 받기  (0) 2018.01.31
전자정부 프레임워크 Ajax 설정  (0) 2018.01.09
Spring properties 설정방법  (0) 2017.10.26

스프링 버전, 전자정부 프레임워크 버전 pom.xml 참고

 

 

 
 
     4.3.4.RELEASE
  3.5.0
  3.0.5    
 

CASE1. josnView 를 이용하여 Ajax 설정방법

- pom.xml

 
         
      net.sf.json-lib
      json-lib       
      2.4       
      jdk15
  

  
   org.codehaus.jackson
   jackson-mapper-asl
   1.9.13
   
- DispatcherServlet XML 설정파일
 
 
 
    
 
- Controller
 
 @RequestMapping(value = "/goAjax3.do", method = RequestMethod.POST)
 public ModelAndView goAjax3() throws Exception{
  ModelAndView mv = new ModelAndView("jsonView");
  mv.addObject("AA", "1");
  mv.addObject("BB", "2");
  return mv;
 } 

CASE2. @ResponseBody 를 이용하여 Ajax 설정방법

- pom.xml

 

     com.fasterxml.jackson.core
     jackson-core
     2.8.8


     com.fasterxml.jackson.core
     jackson-annotations
     2.8.8
         

     com.fasterxml.jackson.core
     jackson-databind
     2.8.8

또는
 


    org.codehaus.jackson
    jackson-mapper-asl
    1.9.13
 
- DispatcherServlet XML 설정파일 - 꼭필요하다
 
 
- Controller
 
 @RequestMapping(value = "/goAjax1.do", method = RequestMethod.POST)
 public @ResponseBody Map goAjax1() throws Exception {
  Map map = new HashMap();
  map.put("AA", "1");
  map.put("BB", "2");
  map.put("CC", "3");
  map.put("DD", "4");
  return map;
 }
 
 @RequestMapping(value = "/goAjax2.do", method = RequestMethod.POST)
 @ResponseBody
 public Map goAjax2() throws Exception{
  Map map = new HashMap();
  map.put("AA", "1");
  map.put("BB", "2");
  return map;
 } 
CASE3. @Controller 를 @RestController 으로 변경함 Spring 4.0은 @Controller와 @ResponseBody 을 합쳐놓은것 이상의 역할을 수행함

'프로그래밍 > Spring' 카테고리의 다른 글

Ajax JSON 데이터 주고 받기  (0) 2018.01.31
Ajax JSON Map 타입으로 넘기고 받기  (0) 2018.01.30
Spring properties 설정방법  (0) 2017.10.26

 

 

 

 

context-common.xml 설정 일부분