본문 바로가기
목차
Spring

Spring MVC (스프링 웹 MVC) 강의 08 - ViewResolver 사용하기

by 지각생 2022. 1. 4.
728x90

viewResolver는 글자 앞뒤 잘라 붙이게 해주는 기능이 있다.

/WEB-INF/view/ 잘라서 앞에 붙이고

.jsp를 뒤에 붙일 것이다. 

 

 

 

 


<bean id="/index" class="com.newlecture.web.controller.IndexController">  
        <!-- collaborators and configuration for this bean go here -->
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
     <property name="prefix" value="/WEB-INF/view/"></property>
     <property name="suffix" value=".jsp"></property>
</bean>

public class IndexController implements Controller{

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("index controller");
ModelAndView mv = new ModelAndView("index");
mv.addObject("data", "Hellow Spring MVC~");
//mv.setViewName("/WEB-INF/view/index.jsp");

return mv;
}
}

 

 

 

 

출처 :

https://www.youtube.com/watch?v=J0ZPjJ6-HC4&list=PLq8wAnVUcTFWhDFFmpJ5fUeoJI53Z83g6&index=9 

 

728x90

댓글