주간 베스트 월간 베스트 3개월 베스트 베스트 게시물
연길시 신화서점 조선말 도서

spring ajax - json

hmily1129 | 2013.08.26 22:35:44 댓글: 0 조회: 4795 추천: 0
분류웹 프로그래밍 https://life.moyiza.kr/itstudy/2001795

1. 추가파일
jsckson-all-1.9.8.jar

2. bean 설정
 <bean id="handlerMapping"
  class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"
  p:alwaysUseFullPath="true" />
 <bean
  class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"
  p:alwaysUseFullPath="true">
  <property name="messageConverters">
   <list>
    <bean
     class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean>
   </list>
  </property>
 </bean>

3. 임의의 오브젝트를 넘기면 알아서 JSON으로 반환한다.
@RequestMapping("/hello")
 @ResponseBody
    public List hello() throws Exception {
  
  //현재 요청중인 thread local의 HttpServletRequest 객체 가져오기
   HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
   //HttpSession 객체 가져오기
   HttpSession session = request.getSession();
   //ServletContext 객체 가져오기
   ServletContext conext = session.getServletContext();
  WebApplicationContext wContext = WebApplicationContextUtils.getWebApplicationContext(conext);
   //스프링 빈 가져오기 & casting
  EmpDao sBean = (EmpDao)wContext.getBean("EmpDao");
   List ss = (List)sBean.getNames();
        return ss;
    }

추천 (0) 선물 (0명)
IP: ♡.200.♡.215
3,006 개의 글이 있습니다.
제목 글쓴이 날짜 조회
관리자
2003-09-20
11745
관리자
2003-09-20
11282
관리자
2003-09-20
20350
지구인
2010-08-27
19213
지구인
2009-09-07
13512
SOLIDH
2010-01-29
15489
엔죠라이프
2004-10-07
16603
CHOSUN
2014-01-11
2444
CHOSUN
2014-01-07
2599
CHOSUN
2014-01-07
2386
CHOSUN
2014-01-07
2053
CHOSUN
2014-01-07
1795
CHOSUN
2014-01-07
1615
CHOSUN
2014-01-07
1180
즐거운개굴
2013-09-29
3003
hmily1129
2013-09-03
4913
hmily1129
2013-08-29
5372
hmily1129
2013-08-26
4795
hmily1129
2013-08-25
3638
hmily1129
2013-08-24
4168
hmily1129
2013-08-23
4325
hmily1129
2013-08-23
3601
hmily1129
2013-08-22
1893
hmily1129
2013-08-10
1626
hmily1129
2013-08-05
2156
hmily1129
2013-08-05
2095
hmily1129
2013-07-30
1472
CHOSUN
2013-07-23
1945
모이자 모바일