Use of apache tiles page templates, apachetiles
Jar package maven
<! -- Tiles template --> <dependency> <groupId> org. apache. tiles </groupId> <artifactId> tiles-extras </artifactId> <version> 3.0.5 </version> </dependency>
Springmvc-servlet.xml Configuration
<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> <! -- Define the location of the JSP file --> <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> <! -- Project --> <! -- 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> <! -- Home page user management --> <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"> the controller corresponding to name returns view
Jsp page usage:
<% @ 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>
<Tiles: insertAttribute name = "admin_head">
Summary: I personally think the tiles label is not too convenient. The only thing that is, the template must be a view return, and then various references, and the use of various el expressions, is that the returned view template makes me feel uncomfortable, it is not as flexible as sitemesh. I started to use tiles. Now I want to change it to sitemesh.