전자정부 프레임워크 Ajax 설정
프로그래밍/Spring2018. 1. 9. 17:21
스프링 버전, 전자정부 프레임워크 버전 pom.xml 참고
- DispatcherServlet XML 설정파일
- Controller
또는
- DispatcherServlet XML 설정파일 - 꼭필요하다
- Controller
CASE3. @Controller 를 @RestController 으로 변경함 Spring 4.0은 @Controller와 @ResponseBody 을 합쳐놓은것 이상의 역할을 수행함
1 2 3 4 5 | < properties > < spring.maven.artifact.version >4.3.4.RELEASE</ spring.maven.artifact.version > < egovframework.rte.version >3.5.0</ egovframework.rte.version > < tiles.version >3.0.5</ tiles.version > </ properties > |
CASE1. josnView 를 이용하여 Ajax 설정방법
- pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 | < dependency > < groupid >net.sf.json-lib</ groupid > < artifactid >json-lib</ artifactid > < version >2.4</ version > < classifier >jdk15</ classifier > </ dependency > < dependency > < groupid >org.codehaus.jackson</ groupid > < artifactid >jackson-mapper-asl</ artifactid > < version >1.9.13</ version > </ dependency > |
1 2 3 4 5 | < bean id = "beanNameResolver" class = "org.springframework.web.servlet.view.BeanNameViewResolver" p:order = "0" > < bean id = "jsonView" class = "org.springframework.web.servlet.view.json.MappingJackson2JsonView" > < property name = "contentType" value = "application/json;charset=UTF-8" ></ property > </ bean > </ bean > |
1 2 3 4 5 6 7 | @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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | < dependency > < groupid >com.fasterxml.jackson.core</ groupid > < artifactid >jackson-core</ artifactid > < version >2.8.8</ version > </ dependency > < dependency > < groupid >com.fasterxml.jackson.core</ groupid > < artifactid >jackson-annotations</ artifactid > < version >2.8.8</ version > </ dependency > < dependency > < groupid >com.fasterxml.jackson.core</ groupid > < artifactid >jackson-databind</ artifactid > < version >2.8.8</ version > </ dependency > |
1 2 3 4 5 | < dependency > < groupid >org.codehaus.jackson</ groupid > < artifactid >jackson-mapper-asl</ artifactid > < version >1.9.13</ version > </ dependency > |
1 | <!--?xml:namespace prefix = "mvc" /--> < mvc:annotation-driven ></ mvc:annotation-driven > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | @RequestMapping (value = "/goAjax1.do" , method = RequestMethod.POST) public @ResponseBody Map<string, object= "" > goAjax1() throws Exception { Map map = new HashMap<string, object= "" >(); 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<string, object= "" > goAjax2() throws Exception{ Map map = new HashMap<string, object= "" >(); map.put( "AA" , "1" ); map.put( "BB" , "2" ); return map; } </string,></string,></string,></string,> |
'프로그래밍 > Spring' 카테고리의 다른 글
Ajax JSON 데이터 주고 받기 (0) | 2018.01.31 |
---|---|
Ajax JSON Map 타입으로 넘기고 받기 (0) | 2018.01.30 |
Spring properties 설정방법 (0) | 2017.10.26 |