spring mvc 集成使用tiles

首先参考了这篇博文

 http://my.oschina.net/u/1762138/blog/228739

博文中的架包如下,我用的是Maven

pom.xml
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-api</artifactId>
   <version>1.5.8</version>
  </dependency>
  <dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-log4j12</artifactId>
   <version>1.4.2</version>
  </dependency>
  <!-- tiles -->
  <dependency>
   <groupId>org.apache.tiles</groupId>
   <artifactId>tiles-api</artifactId>
   <version>2.2.1</version>
  </dependency>
  <dependency>
   <groupId>org.apache.tiles</groupId>
   <artifactId>tiles-core</artifactId>
   <version>2.2.1</version>
  </dependency>
  <dependency>
   <groupId>org.apache.tiles</groupId>
   <artifactId>tiles-jsp</artifactId>
   <version>2.2.1</version>
  </dependency>
  <dependency>
   <groupId>org.apache.tiles</groupId>
   <artifactId>tiles-servlet</artifactId>
   <version>2.2.1</version>
  </dependency>
  <dependency>
   <groupId>org.apache.tiles</groupId>
   <artifactId>tiles-template</artifactId>
   <version>2.2.1</version>
  </dependency>
  <!-- commons-beanutils -->
  <dependency>
   <groupId>commons-beanutils</groupId>
   <artifactId>commons-beanutils</artifactId>
   <version>1.8.0</version>
  </dependency>
  <!-- commons-digester -->
  <dependency>
   <groupId>commons-digester</groupId>
   <artifactId>commons-digester</artifactId>
   <version>2.0</version>
   <type>pom</type>
  </dependency>

配置spring mvc 的xml文件 <beans></beans>(ps:下面这段配置要加在 视图解析器 上面)

 <!-- tiles -->
 <bean id="viewResolver"
  class="org.springframework.web.servlet.view.UrlBasedViewResolver">
  <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
 </bean>
 <bean id="tilesConfigurer"
  class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
  <property name="definitions">
   <list>
    <value>/WEB-INF/tiles.xml</value>
   </list>
  </property>
 </bean> 
 
<!-- 视图解析器 -->

 

WEB-INFO下新建一个tiles.xml

<?xml version="1.0" encoding="UTF-8" ?> 
<!DOCTYPE tiles-definitions PUBLIC 
       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" 
       "http://tiles.apache.org/dtds/tiles-config_2_0.dtd"> 
<tiles-definitions> 
    <definition name="layout"  template="/Template/Layout.jsp"> 
        <put-attribute name="header" value="/Template/Header.jsp" /> 
        <put-attribute name="body" value="" />  
     <put-attribute name="footer" value="/Template/Footer.jsp" /> 
     </definition> 
     
    <definition name="HW" extends="layout"> 
       <put-attribute name="body" value="/test.jsp" />  
    </definition>
    
</tiles-definitions>

 

大概意思就是 HW 继承 layout

 

下面看   Controller层

/**
  * *******************************
  * @Description: 测试1 
  * @MethodName test
  ********************************* 
  */
 @RequestMapping(value ="/test")
 public String test() {
  return  "HW";
 }

 

效果

(待添加)

你可能感兴趣的:(Tiles2)