thymeleaf注入springboot
thymeleaf注入springboot需要引入jar:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
在application.properties中添加:
#启动检查
spring.thymeleaf.check-template=true
#模板
spring.thymeleaf.prefix=classpath:/templates/
#文件后缀
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false spring.mvc.view.prefix=/resources/templates/
spring.mvc.view.suffix=.html
spring.mvc.static-path-pattern=/static/**
#spring.resources.static-locations=classpath:/static/
异常错误:
1. Cannot find template location: classpath:/templates/
如果在程序中已经引入templates在application.properties中也引入了thymeleaf则:
问题出在pom.xml resource在移动资源文件时, templates被忽略所致。
<resource>
<directory>src/main/resources</directory>
<includes>
<include>*.*</include>
<include>static/**</include>
<include>template/**</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
2. 同时注意程序的统一拦截器拦截要加载放行
参见拦截器配置方面。
3. 静态资源第一次设置在页面访问可能出现404,可对mvn先进行打包后,再试。
thymeleaf注入springboot的更多相关文章
- redis-手写redis切片和非切片连接池并注入springboot中
spring-data整合了redispool, 并提供redisTemplate使用, 但有时需要用到shradedJedisPool, 就需要手动注入了 手写redispool并注入springb ...
- thymeleaf教程-springboot项目中实现thymeleaf自定义标签
转载: http://www.9191boke.com/466119140.html 91博客网 开始: 在使用thymeleaf的过程中有时候需要公共部分渲染页面,这个时候使用自定义标签实现自 ...
- Thymeleaf 模板 springboot集成使用
一.Thymeleaf是什么? 简单说, Thymeleaf 是一款用于渲染XML/XHTML/HTML5内容的模板引擎,类似我之前用过的FreeMarker .由于它支持 html 原型,然后在 h ...
- SQL盲注、SQL注入 - SpringBoot配置SQL注入过滤器
1. SQL盲注.SQL注入 风险:可能会查看.修改或删除数据库条目和表. 原因:未对用户输入正确执行危险字符清理. 固定值:查看危险字符注入的可能解决方案. 2. pom.xml添加依赖 ...
- SpringBoot学习9:springboot整合thymeleaf
1.创建maven项目,添加项目所需依赖 <!--springboot项目依赖的父项目--> <parent> <groupId>org.springframewo ...
- SpringBoot: 9.整合thymeleaf(转)
1.创建maven项目,添加项目所需依赖 <!--springboot项目依赖的父项目--> <parent> <groupId>org.springframewo ...
- 【Springboot】Springboot整合Thymeleaf模板引擎
Thymeleaf Thymeleaf是跟Velocity.FreeMarker类似的模板引擎,它可以完全替代JSP,相较与其他的模板引擎,它主要有以下几个特点: 1. Thymeleaf在有网络和无 ...
- SpringBoot系列——Thymeleaf模板
前言 thymeleaf是springboot官方推荐使用的java模板引擎,在springboot的参考指南里的第28.1.10 Template Engines中介绍并推荐使用thymeleaf, ...
- java框架之SpringBoot(4)-资源映射&thymeleaf
资源映射 静态资源映射 查看 SpringMVC 的自动配置类,里面有一个配置静态资源映射的方法: @Override public void addResourceHandlers(Resource ...
随机推荐
- XQuery:查询任何可作为 XML 形态呈现的数据,包括数据库
XQuery 也被称为 XML Query,被设计用来查询 XML 数据. 学习这个 需要知道 HTML / XHTML XML / XML 命名空间 XPath XML 实例文档 我们将在下面的例子 ...
- linux vi命令详解
刚开始学着用linux,对vi命令不是很熟,在网上转接了一篇. vi编辑器是所有Unix及Linux系统下标准的编辑器,它的强大不逊色于任何最新的文本编辑器,这里只是简单地介绍一下它的用法和一小部分指 ...
- 冒泡排序到k趟
浙大pat题目 将N个整数按从小到大排序的冒泡排序法是这样工作的:从头到尾比较相邻两个元素,如果前面的元素大于其紧随的后面元素,则交换它们.通过一遍扫描,则最后一个元素必定是最大的元素.然后用同样的方 ...
- JDBC ---获取数据字段 -- 转成map
getConn = JdbcDataBaseUtil.getConnection(user,pwd,serverUrl,mysqDriver); //建立一个结果集,用来保存查询出来的结果 Resul ...
- PHP输出缓存ob系列函数详解
PHP输出缓存ob系列函数详解 ob,输出缓冲区,是output buffering的简称,而不是output cache.ob用对了,是能对速度有一定的帮助,但是盲目的加上ob函数,只会增加CPU额 ...
- jmeter 关联
(1)正则表达式提取器 注:正则表达式部分配置说明 案例: 动态值:name=userSession value=119828.306682868zVzDzzipfcfDzQicpAVVVf> ...
- linux安装redis标准流程-按这个来
1.将下载好的压缩包放到/usr/local目录下# tar xzf redis-3.2.9.tar.gz # cd redis-3.2.9 # make 提示错误 make: cc: Command ...
- 小程序 去掉 <button /> 组件默认 border 边框样式
代码: <button class="btn">点击</button> 效果图: 目的:去掉 <button /> 默认样式中的 backgro ...
- DevExpress破解和消除弹出框问题
在解决方案管理器列表中找到 license.licx 设置属性 将[生成操作]选项改为[无]
- 简述Ajax原理及实现步骤
简述Ajax原理及实现步骤 1.Ajax简介 概念 Ajax 即“Asynchronous Javascript And XML”(异步 JavaScript 和 XML). 现在允许浏览器与务器通信 ...