apache tiles 頁面模板的使用,apachetiles

來源:互聯網
上載者:User

apache tiles 頁面模板的使用,apachetiles

jar包maven

        <!-- Tiles 模板-->        <dependency>              <groupId>org.apache.tiles</groupId>            <artifactId>tiles-extras</artifactId>            <version>3.0.5</version>        </dependency>

springmvc-servlet.xml配置

<bean id="tilesViewResolver"     class="org.springframework.web.servlet.view.UrlBasedViewResolver">      <property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"></property>      <property name="order" value="1" /> </bean>  <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">        <property name="definitions">            <list>                <value>classpath:layout.xml</value>            </list>        </property></bean>    <!-- 定義JSP檔案的位置 -->     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">        <property name="prefix" value="/WEB-INF/pages/"/>        <property name="suffix" value=".jsp"/>         <property name="order" value="1" />    </bean>

layout.xml

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE tiles-definitions PUBLIC     "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"     "http://tiles.apache.org/dtds/tiles-config_3_0.dtd"><tiles-definitions>  <!--項目-->  <!-- admin -->  <!-- admin base -->  <definition name="base_admin">      <put-attribute name="admin_head" value="/WEB-INF/pages/common/template/admin/adminHead.jsp"></put-attribute>      <put-attribute name="admin_left" value="/WEB-INF/pages/common/template/admin/adminLeft.jsp"></put-attribute>  </definition>    <!-- 首頁 使用者管理 -->  <definition name="index" template="/WEB-INF/pages/index.jsp" extends="base_admin">      <put-attribute name="flag" type="string" value="1"></put-attribute>  </definition></tiles-definitions>
<definition name="base_admin"> name 對應的controller返回view


jsp頁面使用:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%----%><%@ include file="/WEB-INF/pages/common/taglibs.jsp"%><%----%><%@ include file="/WEB-INF/pages/common/resource.jsp"%><%----%><!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"/><title>首頁</title>${css_main}${css_bootstrap}${js_jquery}<script type="text/javascript" src="/resources/module/admin/index.js"></script></head><body>    <div class="container">        <div class="row">            <tiles:insertAttribute name="admin_head"></tiles:insertAttribute><!-- left --><div class="row">    <tiles:insertAttribute name="admin_left"></tiles:insertAttribute><div class="col-xs-10"><input type="hidden" value="<tiles:getAsString name="flag"/>" id="leftv"/><!--right-->    <table class="table table-hover table-striped table-bordered">      <tr>          <td>使用者名稱</td>          <td>建立時間</td>          <td>333</td>      </tr>      <c:forEach var="u" items="${listUser}">      <tr>          <td>${u.userName}</td>          <td>${u.createDate}</td>          <td>333</td>      </tr>      </c:forEach></table></div></div>        </div>    </div>    <script type="text/javascript">            </script></body></html>

通過<tiles:insertAttribute name="admin_head">就可以引用了

 

總結:個人感覺tiles標籤不是太方便唯一一點就是模板必須是視圖返回,然後各種引用,還有各種el運算式的使用,就是返回視圖返回模板讓我感覺到了不爽,沒有sitemesh那麼靈活,開始用的tiles用了,現在準備又換到sitemesh試試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.