2013-06-27 6 views
1

저는 컨트롤러가 없기 때문에 viewname을 모델 객체로 설정하고 리턴합니다. 이 메소드가 없다면 SpringMVC는 타일 정의를 통해 직접 매핑을 수행합니까? 그렇다면 어떻게 할 수 있는지 알려주십시오. 당신은 org.springframework.web.servlet.handler.SimpleUrlHandlerMapping & org.springframework.web.servlet.mvc.UrlFilenameViewController의 조합을 사용할 수 있습니다SpringMVC는 컨트롤러 메소드없이 타일 정의의 로딩을 지원합니까?

답변

0

사전에

감사합니다 .. :

  • SimpleUrlHandlerMapping는 컨트롤러에 직접 연결 URL을 수있는 기능을 제공을
  • UrlFilenameViewController는 수신 URL을 변환 (예 : URL: /test.htmlView name: test).

이하, 필요한 Spring 설정 :

<?xml version="1.0" encoding="UTF-8"?> 
    <beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:util="http://www.springframework.org/schema/util" 
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
      http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd 
      http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
      http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.2.xsd"> 

     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
      <property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" /> 
      <property name="prefix" value="/WEB-INF/tiles/" /> 
      <property name="suffix" value=".tiles" /> 
      <property name="order" value="1" /> 
     </bean> 

     <!-- For direct mapping between URL (i.e. index.html ←→ index) and the JSP 
      to render --> 
     <bean id="urlFilenameViewController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController" /> 

     <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
      <property name="order" value="1" /> 
      <property name="mappings"> 
       <util:map> 
        <entry key="/test.html" value-ref="urlFilenameViewController" /> 
       </util:map> 
      </property> 
     </bean> 
    </beans> 

귀하의 봄 구성에서 <mcv:default-servlet-handler /> 태그의주의, 그것은 (널 (null) 및 기본 핸들러의 우선 순위로 Interger.MAX_VALUE로 설정 반환하지 않음으로 위의 구성을 할 수 있습니다 스프링 문서에서 설명했다).