Spring boot 整合jsp和tiles模板
首先贴上我的pox.xml文件,有详细的支持注释说明
<?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和数据库 -->
<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>
<!--添加访问设备识别支持 -->
<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>
在application.properties文件中需要加入配置如下
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
1.接下来我们写一个titles支持的模板jsp
<%@ 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>
2.现在可以写一个整合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;
}
}
http://www.kailing.pub/article/index/arcid/60.html
Spring boot 整合jsp和tiles模板的更多相关文章
- spring boot整合jsp的那些坑(spring boot 学习笔记之三)
Spring Boot 整合 Jsp 步骤: 1.新建一个spring boot项目 2.修改pom文件 <dependency> <groupId>or ...
- Spring boot整合jsp
这几天在集中学习Spring boot+Shiro框架,因为之前view层用jsp比较多,所以想在spring boot中配置jsp,但是spring boot官方不推荐使用jsp,因为jsp相对于一 ...
- 从零开始的Spring Boot(4、Spring Boot整合JSP和Freemarker)
Spring Boot整合JSP和Freemarker 写在前面 从零开始的Spring Boot(3.Spring Boot静态资源和文件上传) https://www.cnblogs.com/ga ...
- Spring Boot学习总结(2)——Spring Boot整合Jsp
怎么使用jsp上面起了疑问,查阅了多方资料,找到过其他人的博客的描述,也找到了spring在github上的给出的例子,看完后稍微改动后成功 整合jsp,于是决定将整合过程记载下来. 无论使用的是那种 ...
- Spring boot 整合jsp、thymeleaf、freemarker
1.创建spring boot 项目 2.pom文件配置如下: <dependencies> <dependency> <groupId>org.springfra ...
- Spring boot 整合JSP开发步骤
1. 新建Springboot项目,war <dependency> <groupId>org.springframework.boot</groupId> < ...
- 峰哥说技术:09-Spring Boot整合JSP视图
Spring Boot深度课程系列 峰哥说技术—2020庚子年重磅推出.战胜病毒.我们在行动 09 峰哥说技术:Spring Boot整合JSP视图 一般来说我们很少推荐大家在Spring boot ...
- Spring Boot 整合视图层技术,application全局配置文件
目录 Spring Boot 整合视图层技术 Spring Boot 整合jsp Spring Boot 整合freemarker Spring Boot 整合视图层技术 Spring Boot 整合 ...
- 从零开始的Spring Boot(5、Spring Boot整合Thymeleaf)
Spring Boot整合Thymeleaf 写在前面 从零开始的Spring Boot(4.Spring Boot整合JSP和Freemarker) https://www.cnblogs.com/ ...
随机推荐
- 揭开NodeJS的神秘面纱!
一.NodeJS是什么? Node是一个服务器端JavaScript解释器.Node.js是一套用来编写高性能网络服务器的JavaScript包. 二.Node的目标是什么? Node 公开宣称的目标 ...
- windows 2008 下C#调用office组件访问拒绝的解决方法(failed due to the following error: 80070005 拒绝访问)
"组件服务"- >"计算机"- >"我的电脑"- >"DCOM配置"->找到word->属 ...
- android 开发 socket发送会有部分乱码,串码,伴随着数据接收不完整
场景: 客户端A.B,A向B发送json字符串后紧接着发送文件,B接收到文件后才返回消息. 环境:android.使用的是原始的write 和read (若使用的是writeUTF不会出现此问题.)需 ...
- LESS CSS 框架简介
使用 LESS 简化层叠样式表(CSS)的编写 LESS 是动态的样式表语言,通过简洁明了的语法定义,使编写 CSS 的工作变得非常简单.本文将通过实例,为大家介绍这一框架. 简介 CSS(层叠样式表 ...
- BZOJ1565 植物大战僵尸
AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=1565 这题看上去并不会做,结果又是最大权闭合子图的裸题. 于是就去看了一发论文,明白建图的 ...
- ios 百度地图
百度地图 中的注意事项 1. 百度地图中 使用了c++ 设置buidSeting compoileSource 为 Object-C++ 强制使用oc++编译器 2. 设置 BuidSeti ...
- Javascript动态生成表格的性能调优
vision 0.8 [耗时672ms]终极优化 将字符串作为数组对象的方式是目前效率最高,性能最优的方式. <script> var t1 = new Date(); < ...
- 驱动笔记 - Makefile
ifneq ($(KERNELRELEASE),) obj-m := hello.ohello-objs := main.o add.o else KDIR := /lib/modules/2.6.1 ...
- IOS 提交审核,遇到Missing Push Notification Entitlement 问题。
貌似不影响提交........还是有人提交成了. 昨天晚上提交软件审核,遇到了Missing Push Notification Entitlement 的问题. 问题起因:这个版本我添加了PUSH推 ...
- vi/vim使用指北 ---- Introducting the ex Editor
本章介绍ex编辑器,为什么要介绍这样一个新的编辑器呢:其实ex编辑器不能算是一个新的编辑器,vi只是它的visual model,它已经是一个更普遍,基于行的编辑器.ex提供更大机动和范围的编辑命令. ...