您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
小编给大家分享一下Spring mvc如何整合tiles框架,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
先贴上源码:
1、tiles依赖的jar包:
maven代码:
<dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils-core</artifactId> <version>1.8.3</version> </dependency> <dependency> <groupId>commons-digester</groupId> <artifactId>commons-digester</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.15</version> </dependency> <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> <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>
2、Spring mvc 中配置Tiles框架(springmvc-servlet.xml)
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass"> <value> org.springframework.web.servlet.view.tiles2.TilesView </value> </property> </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>
3、配置tiles (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="base.definition" template="/jsp/templet.jsp"> <put-attribute name="title" value="" /> <put-attribute name="header" value="/jsp/head.jsp" /> <put-attribute name="menu" value="/jsp/menu.jsp" /> <put-attribute name="body" value="" /> <put-attribute name="footer" value="/jsp/foot.jsp" /> </definition> <definition name="CustomerForm" extends="base.definition"> <put-attribute name="title" value="HHHHHHH"/> <put-attribute name="body" value="/jsp/CustomerForm.jsp"/> </definition> <definition name="CustomerDetail" extends="base.definition"> <put-attribute name="title" value="DDDDDD"/> <put-attribute name="body" value="/jsp/CustomerDetail.jsp"/> </definition> </tiles-definitions>
其中templet.jsp(base.definition)作为模板,其中定义的header,menu,body,footer都需要自己配置相应的jsp文件,一般body为可变的,其他为固定的jsp。
templet.jsp代码:
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%> <%@ page language="java" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title><tiles:insertAttribute name="title" ignore="true" /></title> </head> <body> <table border="1" cellpadding="2" cellspacing="2" align="center"> <tr> <td height="30" colspan="2"><tiles:insertAttribute name="header" /> </td> </tr> <tr> <td height="250" width="200"><tiles:insertAttribute name="menu" /></td> <td width="600"><tiles:insertAttribute name="body" /></td> </tr> <tr> <td height="30" colspan="2"><tiles:insertAttribute name="footer" /> </td> </tr> </table> </body> </html> <h2>Bottom</h2> <span ><p><a href="http://www.qlysou.com/">www.qlysou.com</a></p></span> <span ><p>Copyright <code class="xml plain">©</code><a href="http://www.qlysou.com/">www.qlysou.com</a> </p></span>
4.效果
以上是“Spring mvc如何整合tiles框架”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。