springboot中jsp配置tiles全過(guò)程
tiles是jsp的前端框架;像fream標(biāo)簽一樣可以把多個(gè)頁(yè)面組合起來(lái);
完成后的目錄結(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"; //這個(gè)是 definition 的 name="site.homepage" } }
6.測(cè)試
完成!
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot集成JWT實(shí)現(xiàn)token驗(yàn)證的流程
Json web token (JWT), 是為了在網(wǎng)絡(luò)應(yīng)用環(huán)境間傳遞聲明而執(zhí)行的一種基于JSON的開放標(biāo)準(zhǔn)((RFC 7519).這篇文章主要介紹了SpringBoot集成JWT實(shí)現(xiàn)token驗(yàn)證,需要的朋友可以參考下2020-01-01springboot dynamic多數(shù)據(jù)源demo以及常見切換、事務(wù)的問(wèn)題
這篇文章主要介紹了springboot dynamic多數(shù)據(jù)源demo以及常見切換、事務(wù)的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07SpringBoot DBUnit 單元測(cè)試(小結(jié))
這篇文章主要介紹了SpringBoot DBUnit 單元測(cè)試(小結(jié)),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-09-09SpringBoot接口惡意刷新和暴力請(qǐng)求的解決方法
在實(shí)際項(xiàng)目使用中,必須要考慮服務(wù)的安全性,當(dāng)服務(wù)部署到互聯(lián)網(wǎng)以后,就要考慮服務(wù)被惡意請(qǐng)求和暴力攻擊的情況,所以本文給大家介紹了SpringBoot接口惡意刷新和暴力請(qǐng)求的解決方法,需要的朋友可以參考下2024-11-11java常用Lambda表達(dá)式使用場(chǎng)景源碼示例
這篇文章主要為大家介紹了java常用Lambda表達(dá)式使用場(chǎng)景源碼示例及應(yīng)用解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2022-03-03基于Java注解(Annotation)的自定義注解入門介紹
要深入學(xué)習(xí)注解,我們就必須能定義自己的注解,并使用注解,在定義自己的注解之前,我們就必須要了解Java為我們提供的元注解和相關(guān)定義注解的語(yǔ)法2013-04-04Spring使用aop切面編程時(shí)要給那些類加注解的實(shí)例
在使用切面編程時(shí),通常需要為以下類或組件添加注解來(lái)標(biāo)識(shí)它們,以便 Spring 或其他切面框架能夠正確識(shí)別和處理它們,這篇文章主要介紹了Spring使用aop切面編程時(shí)要給那些類加注解,需要的朋友可以參考下2023-11-11詳解Java時(shí)區(qū)處理之Date,Calendar,TimeZone,SimpleDateFormat
這篇文章主要介紹了Java時(shí)區(qū)處理之Date,Calendar,TimeZone,SimpleDateFormat的區(qū)別于用法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07