springboot中jsp配置tiles全過程
tiles是jsp的前端框架;像fream標(biāo)簽一樣可以把多個(gè)頁(yè)面組合起來;
完成后的目錄結(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)文章
IDEA創(chuàng)建方法時(shí)如何快速添加注釋
這篇文章主要介紹了IDEA創(chuàng)建方法時(shí)如何快速添加注釋問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02
Java 中HttpURLConnection附件上傳的實(shí)例詳解
這篇文章主要介紹了Java 中HttpURLConnection附件上傳的實(shí)例詳解的相關(guān)資料,希望通過本文大家能掌握這樣的知識(shí)內(nèi)容,需要的朋友可以參考下2017-09-09
使用Spring AntPathMatcher的doMatch方法
這篇文章主要介紹了使用Spring AntPathMatcher的doMatch方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-09-09
Spring?Boot?@Autowired?@Resource屬性賦值時(shí)機(jī)探究
這篇文章主要為大家介紹了Spring?Boot?@Autowired?@Resource屬性賦值時(shí)機(jī),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-07-07
使用@Validated和@Valid 解決list校驗(yàn)的問題
這篇文章主要介紹了使用@Validated和@Valid 解決list校驗(yàn)的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-10-10
SpringBoot2零基礎(chǔ)到精通之異常處理與web原生組件注入
SpringBoot是Spring全家桶的成員之一,基于約定優(yōu)于配置的思想(即有約定默認(rèn)值,在不配置的情況下會(huì)使用默認(rèn)值,在配置文件下配置的話會(huì)使用配置的值)。SpringBoot是一種整合Spring技術(shù)棧的方式(或者說是框架),同時(shí)也是簡(jiǎn)化Spring的一種快速開發(fā)的腳手架2022-03-03

