springboot中jsp配置tiles全過程
tiles是jsp的前端框架;像fream標簽一樣可以把多個頁面組合起來;
完成后的目錄結(jié)構(gòu):
1.pom.xml中添加依賴
<!-- Add Apache Tiles into the mix --> <dependency> <groupId>org.apache.tiles</groupId> <artifactId>tiles-jsp</artifactId> <version>3.0.4</version> </dependency>
2.新建 tiles.xml
可以放在WEB-INF/tiles/目錄里
<?xml version="1.0" encoding="ISO-8859-1" ?> <!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> <!-- Templates --> <definition name="layout.basic" template="/WEB-INF/tiles/basic.jsp"> <put-attribute name="title" value="Spring Web MVC with Tiles 3" /> <put-attribute name="header" value="/WEB-INF/tiles/header.jsp" /> <put-attribute name="body" value="" /> <put-attribute name="footer" value="/WEB-INF/tiles/footer.jsp" /> </definition> <!-- Pages --> <definition name="site.homepage" extends="layout.basic"> <put-attribute name="body" value="/WEB-INF/tiles/home.jsp" /> </definition> </tiles-definitions>
3.新建tiles配置類ConfigurationForTiles.java
@Configuration public class ConfigurationForTiles { /** * Initialise Tiles on application startup and identify the location of the tiles configuration file, tiles.xml. * * @return tiles configurer */ @Bean public TilesConfigurer tilesConfigurer() { final TilesConfigurer configurer = new TilesConfigurer(); configurer.setDefinitions(new String[] { "WEB-INF/tiles/tiles.xml" }); configurer.setCheckRefresh(true); return configurer; } /** * Introduce a Tiles view resolver, this is a convenience implementation that extends URLBasedViewResolver. * * @return tiles view resolver */ @Bean public TilesViewResolver tilesViewResolver() { final TilesViewResolver resolver = new TilesViewResolver(); resolver.setViewClass(TilesView.class); return resolver; } }
注意tiles.xml文件目錄要正確;
4.jsp
1. basic.jsp
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%> <html> <head> <title><tiles:getAsString name="title" /></title> </head> <body> basic.jsp <!-- Header --> <tiles:insertAttribute name="header" /> <!-- Body --> <tiles:insertAttribute name="body" /> <!-- Footer --> <tiles:insertAttribute name="footer" /> </body> </html>
2.footer.jsp
<div>The Footer footer.jsp</div>
3.header.jsp
<div>The Header header.jsp</div>
4.home.jsp
<div> Main content would go here. Lets try. home.jsp </div>
5.控制類
@Controller public class GreetingController { private Log log = LogFactory.getLog(this.getClass()); @RequestMapping(value = "/home", method=RequestMethod.GET) public String home() { return "site.homepage"; //這個是 definition 的 name="site.homepage" } }
6.測試
完成!
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot集成JWT實現(xiàn)token驗證的流程
Json web token (JWT), 是為了在網(wǎng)絡(luò)應(yīng)用環(huán)境間傳遞聲明而執(zhí)行的一種基于JSON的開放標準((RFC 7519).這篇文章主要介紹了SpringBoot集成JWT實現(xiàn)token驗證,需要的朋友可以參考下2020-01-01springboot dynamic多數(shù)據(jù)源demo以及常見切換、事務(wù)的問題
這篇文章主要介紹了springboot dynamic多數(shù)據(jù)源demo以及常見切換、事務(wù)的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07SpringBoot DBUnit 單元測試(小結(jié))
這篇文章主要介紹了SpringBoot DBUnit 單元測試(小結(jié)),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09基于Java注解(Annotation)的自定義注解入門介紹
要深入學(xué)習(xí)注解,我們就必須能定義自己的注解,并使用注解,在定義自己的注解之前,我們就必須要了解Java為我們提供的元注解和相關(guān)定義注解的語法2013-04-04詳解Java時區(qū)處理之Date,Calendar,TimeZone,SimpleDateFormat
這篇文章主要介紹了Java時區(qū)處理之Date,Calendar,TimeZone,SimpleDateFormat的區(qū)別于用法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07