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;
}
제목 | 글쓴이 | 날짜 | 조회 |
---|---|---|---|
2003-09-20 |
11745 |
||
2003-09-20 |
11282 |
||
2003-09-20 |
20350 |
||
지구인 |
2010-08-27 |
19213 |
|
지구인 |
2009-09-07 |
13512 |
|
2010-01-29 |
15489 |
||
2004-10-07 |
16603 |
||
2014-01-11 |
2444 |
||
2014-01-07 |
2599 |
||
2014-01-07 |
2386 |
||
2014-01-07 |
2053 |
||
2960 [공개소스] 그누보드 4.36.27 |
2014-01-07 |
1795 |
|
2959 [공개소스] 그누보드 4.36.26 |
2014-01-07 |
1615 |
|
2958 [공개소스] 그누보드 4.36.25 |
2014-01-07 |
1180 |
|
즐거운개굴 |
2013-09-29 |
3003 |
|
2013-09-03 |
4913 |
||
2955 [웹 프로그래밍] ajax 특수문자 |
2013-08-29 |
5372 |
|
2013-08-26 |
4795 |
||
2013-08-25 |
3638 |
||
2013-08-24 |
4168 |
||
2013-08-23 |
4325 |
||
2013-08-23 |
3601 |
||
2013-08-22 |
1893 |
||
2948 [웹 프로그래밍] log4j |
2013-08-10 |
1626 |
|
2013-08-05 |
2156 |
||
2946 [웹 프로그래밍] Spring 기초 |
2013-08-05 |
2095 |
|
2013-07-30 |
1472 |
||
2013-07-23 |
1945 |