1. pom.xml

 

아래 기존 jackson 1.x 버전은

<dependency>

<groupId>org.codehaus.jackson</groupId>

<artifactId>jackson-mapper-asl</artifactId>

<version>1.9.2</version>

</dependency>

보안이슈가 있으므로 스프링 4.x 부터   jackson 2.x 로 변경해줌.

 

		<dependency>
		       <groupId>com.fasterxml.jackson.core</groupId>
		      <artifactId>jackson-core</artifactId>
		      <version>2.9.10</version>
		</dependency>
		<dependency>
		  <groupId>com.fasterxml.jackson.core</groupId>
		  <artifactId>jackson-databind</artifactId>
		  <version>2.9.10</version>
		</dependency>
		<dependency>
		    <groupId>com.fasterxml.jackson.core</groupId>
		    <artifactId>jackson-annotations</artifactId>
		    <version>2.9.10</version>
		</dependency>

 

 

2. WEB-INF/config/egovframework/springmvc/egov-com-servlet.xml

 

기존 : 

	<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="0"/>

	<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" p:order="1" 
    p:prefix="/WEB-INF/jsp/" 
    p:suffix=".jsp" 
    p:viewClass="org.springframework.web.servlet.view.JstlView"/>

 

 

변경 : jsonView 추가 및 order 순서 변경

 

    
	<bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
	
		<property name="contentType" value="application/json;charset=UTF-8" />

	</bean>
   
    <bean class="org.springframework.web.servlet.view.BeanNameViewResolver">
		<property name="order" value="1">
	</property></bean>
	

    <!-- 화면처리용 JSP 파일명의  prefix, suffix 처리에 대한 mvc 설정  -->
    <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" p:order="2"
	    p:viewClass="org.springframework.web.servlet.view.JstlView"
	    p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
    		

 

3. Controller

 

ModelAndView 형태의 메소드 사용

@RequestMapping(value="/test.do", method=RequestMethod.POST)
	public ModelAndView testList(
			@RequestParam(value="test", required=false) final String test,
            @ModelAttribute("TestVO") TestVO testVO, 
			HttpServletRequest request, HttpServletResponse response, ModelMap model) throws Exception {
				
		
				
		//검색 목록
		List<TestVO> result = testService.testList(testVO);
		
		int resultCnt = testService.testListCnt(testVO);
		

		ModelAndView mav = new ModelAndView("jsonView");
		mav.addObject("resultList", result);		//목록리스트
		mav.addObject("resultCnt", resultCnt);		//목록 수
		mav.addObject("testVO", testVO);	//해당 VO

		
		return mav;
		
		
	}

 

블로그 이미지

엘로드넷

댓글을 달아 주세요