2010-07-23 4 views
1

누구나 내가 Spring MVC 애플리케이션에서 데이터 교환을 위해 JSON 라이브러리를 사용하여 Ajax를 통합 할 수있는 튜토리얼을 제안 할 수 있는가? 나는spring ajax json jquery

답변

2
+0

입니다 .. 이 자습서에서 언급 한 flexjson.JSONSerializer 클래스가 포함되어 있습니까? 아니면 모두 다 다르지? – apoorva

+0

flexjson은 http://flexjson.sourceforge.net/에서 추가 라이브러리입니다. – JoseK

+0

어느 것이 좋습니다? Flexjson 또는 spring-json ?? flexjson 라이브러리 어디서든지 플렉스와 관련된 무엇입니까 ??? – apoorva

1

http://api.jquery.com/jQuery.ajax/ , 을 가지고 내 응용 프로그램에서 아약스와 jQuery를 사용해야합니다 그러면 웹 페이지에서이 서비스로 아약스를 호출 한 다음이 서비스 json에서 돌아와 매우 쉽게 파싱 할 수 있습니다. 내가 도울 수있는 경우 찾을 수 있습니다.

내부 스프링 쓰기 어이 서비스

@GET 
    @Produces({MediaType.APPLICATION_JSON}) 
    @Path("getAllAlbums") 
    public String getAllAlbums() { 
     List<Album> albums = photoService.getAlbums(); 
     String albumListasJson = jgen.getFilteredJsonString(albums); 
     return albumListasJson; 
    } 

처럼이 내가 json2.2.3 jar 파일을 다운로드했다 ... 나는이 자습서를 시도 JSON 라이브러리

<dependency> 
      <groupId>net.sf.json-lib</groupId> 
      <artifactId>json-lib</artifactId> 
      <classifier>jdk15</classifier> 
      <version>2.4</version> 
     </dependency> 

와 아약스 측

function getAlbums(){ 
    $.ajax({ 
     type:  "GET", 
     url:  "../rest/xxxx/" + userID, 
     dataType:  "text", //"json" 
     cache :  "false", 
     //content :  "document.body", 
     success:  function(msg) { 
      albums = "{\"albums\":" + msg + "}"; 
      tplAlb = tmpls['viewId-01']; 
      if (tplAlb && albums) { 
       data = JSON.parse(aaaa); 
       if (data.albums.length == 0) { 
        $.post("../rest/cccccc/" + userID + "/" + "aaaaaaa"); 
        getAlbums(); 
       } 
//    alert(data.albums.length); 

      } 
     } 
    }); 
}