欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Spring?boot整合jsp和tiles模板示例

 更新時間:2022年03月08日 14:24:33   作者:kl  
這篇文章主要介紹了Spring?boot整合jsp模板和tiles模板的示例演示過程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

首先貼上我的pox.xml文件,有詳細(xì)的支持注釋說明

<strong><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<artifactId>demo</artifactId>
	<version>1.0.1-SNAPSHOT</version>
	<name>demo</name>
	<repositories>
		<repository>
			<id>nexus</id>
			<name>local private nexus</name>
			<url>http://maven.oschina.net/content/groups/public/</url>
		</repository>
		<repository>
			<id>spring-maven-release</id>
			<name>Spring Maven Release Repository</name>
			<url>http://maven.springframework.org/release</url>
		</repository>
		<repository>
			<id>spring-maven-milestone</id>
			<name>Spring Maven Milestone Repository</name>
			<url>http://maven.springframework.org/milestone</url>
		</repository>
		<repository>
			<id>mynexus</id>
			<name>my internal repository</name>
			<url>http://116.236.223.116:8082/nexus/content/groups/public/</url>
		</repository>
	</repositories>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.3.0.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<java.version>1.7</java.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-logging</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<!--jpa和數(shù)據(jù)庫 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
			<exclusions>
				<exclusion>
					<artifactId>jcl-over-slf4j</artifactId>
					<groupId>org.slf4j</groupId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
		</dependency>
		<dependency>
			<groupId>commons-dbcp</groupId>
			<artifactId>commons-dbcp</artifactId>
		</dependency>
		<!--測試 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-logging</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>com.github.sgroschupf</groupId>
			<artifactId>zkclient</artifactId>
			<version>0.1</version>
		</dependency>
		<dependency>
			<groupId>com.xr</groupId>
			<artifactId>xuri-rpc-api</artifactId>
			<version>1.0.1-SNAPSHOT</version>
		</dependency>
		<!--添加tiles布局模板支持 -->
		<dependency>
			<groupId>org.apache.tiles</groupId>
			<artifactId>tiles-jsp</artifactId>
			<version>3.0.5</version>
		</dependency>
		<!--添加jstl -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
		</dependency>
		<!--添加對jsp的支持 -->
		<dependency>
			<groupId>org.apache.tomcat.embed</groupId>
			<artifactId>tomcat-embed-jasper</artifactId>
			<scope>provided</scope>
		</dependency>
		<!--添加訪問設(shè)備識別支持 -->
		<dependency>
			<groupId>org.springframework.mobile</groupId>
			<artifactId>spring-mobile-device</artifactId>
		</dependency>
		<dependency>
			<groupId>org.json</groupId>
			<artifactId>json</artifactId>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<!-- -->
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<executions>
					<execution>
						<goals>
							<goal>repackage</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<!--maven install時 跳過單元測試 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<skip>true</skip>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<packaging>war</packaging>
</project> 
</strong>

在application.properties文件中需要加入配置如下

<strong>spring.mvc.view.prefix=/WEB-INF/jsp/ spring.mvc.view.suffix=.jsp</strong>

1.接下來我們寫一個titles支持的模板jsp

<strong><%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<html>
	<head>
		<title><tiles:getAsString name="title" /></title>
	</head>
	<body>
		<!-- Header 可以被put-attribute name="header” value 所描述的文件替換-->
		<tiles:insertAttribute name="header" /> 
		<!-- Body -->
		<tiles:insertAttribute name="body" />
		<!-- Footer -->
		<tiles:insertAttribute name="footer" />
	</body>
</html>
</strong>

2.現(xiàn)在可以寫一個整合titles的配置文件了tiles.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>
	<!-- Templates -->
	<definition name="layout.basic" template="/WEB-INF/jsp/layout/basic.jsp">
		<put-attribute name="title" value="Spring Web MVC with Tiles 3" />
		<put-attribute name="header" value="/WEB-INF/jsp/view/header.jsp" />
		<put-attribute name="body" value="" />
		<put-attribute name="footer" value="/WEB-INF/jsp/view/footer.jsp" />
	</definition>
			<!-- Pages -->	
	<definition name="site.greeting" extends="layout.basic">
		<put-attribute name="body" value="/WEB-INF/tiles/view/home/greeting.jsp" />
	</definition>
</tiles-definitions>

 3.最后我們需要加載titles.xml文件

@Configuration
public class ConfigurationForTiles {
    @Bean
    public TilesConfigurer tilesConfigurer() {
        final TilesConfigurer configurer = new TilesConfigurer();
        configurer.setDefinitions(new String[] { "WEB-INF/jsp/tiles.xml" });
        configurer.setCheckRefresh(true);
        return configurer;
    }
    @Bean
    public TilesViewResolver tilesViewResolver() {
        final TilesViewResolver resolver = new TilesViewResolver();
        resolver.setViewClass(TilesView.class);
        return resolver;
    }
}

以上就是Spring boot整合jsp和tiles模板示例的詳細(xì)內(nèi)容,更多關(guān)于Spring boot整合jsp和tiles模板的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • SpringBoot讀寫操作yml配置文件方法

    SpringBoot讀寫操作yml配置文件方法

    之前一直用的application.properties配置文件,只能是KV結(jié)構(gòu),后來的yml配置文件更像是樹狀結(jié)構(gòu),支持層級,比properties更靈活
    2023-01-01
  • SpringCloud Gateway的路由,過濾器和限流解讀

    SpringCloud Gateway的路由,過濾器和限流解讀

    這篇文章主要介紹了SpringCloud Gateway的路由,過濾器和限流解讀,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-02-02
  • 手?jǐn)]一個 spring-boot-starter的全過程

    手?jǐn)]一個 spring-boot-starter的全過程

    這篇文章主要介紹了手?jǐn)]一個 spring-boot-starter的全過程,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-01-01
  • 詳解SpringBoot通過restTemplate實(shí)現(xiàn)消費(fèi)服務(wù)

    詳解SpringBoot通過restTemplate實(shí)現(xiàn)消費(fèi)服務(wù)

    本篇文章主要介紹了詳解使用RestTemplate消費(fèi)spring boot的Restful服務(wù),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • Java中volatile關(guān)鍵字的作用與用法詳解

    Java中volatile關(guān)鍵字的作用與用法詳解

    volatile關(guān)鍵字雖然從字面上理解起來比較簡單,但是要用好不是一件容易的事情。這篇文章主要介紹了Java中volatile關(guān)鍵字的作用與用法詳解的相關(guān)資料,需要的朋友可以參考下
    2016-09-09
  • JavaWeb?使用DBUtils實(shí)現(xiàn)增刪改查方式

    JavaWeb?使用DBUtils實(shí)現(xiàn)增刪改查方式

    這篇文章主要介紹了JavaWeb?使用DBUtils實(shí)現(xiàn)增刪改查方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • java模擬實(shí)現(xiàn)銀行ATM機(jī)操作

    java模擬實(shí)現(xiàn)銀行ATM機(jī)操作

    這篇文章主要為大家詳細(xì)介紹了java模擬實(shí)現(xiàn)銀行ATM機(jī)操作,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • 通過代碼實(shí)例了解SpringBoot啟動原理

    通過代碼實(shí)例了解SpringBoot啟動原理

    這篇文章主要介紹了通過代碼實(shí)例了解SpringBoot啟動原理,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-12-12
  • java 定義長度為0的數(shù)組/空數(shù)組案例

    java 定義長度為0的數(shù)組/空數(shù)組案例

    這篇文章主要介紹了java 定義長度為0的數(shù)組/空數(shù)組案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-03-03
  • springBoot整合Eureka啟動失敗的解決方案

    springBoot整合Eureka啟動失敗的解決方案

    這篇文章主要介紹了springBoot整合Eureka啟動失敗的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07

最新評論