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的更多相关文章

  1. redis-手写redis切片和非切片连接池并注入springboot中

    spring-data整合了redispool, 并提供redisTemplate使用, 但有时需要用到shradedJedisPool, 就需要手动注入了 手写redispool并注入springb ...

  2. thymeleaf教程-springboot项目中实现thymeleaf自定义标签

    转载: http://www.9191boke.com/466119140.html    91博客网 开始: 在使用thymeleaf的过程中有时候需要公共部分渲染页面,这个时候使用自定义标签实现自 ...

  3. Thymeleaf 模板 springboot集成使用

    一.Thymeleaf是什么? 简单说, Thymeleaf 是一款用于渲染XML/XHTML/HTML5内容的模板引擎,类似我之前用过的FreeMarker .由于它支持 html 原型,然后在 h ...

  4. SQL盲注、SQL注入 - SpringBoot配置SQL注入过滤器

    1. SQL盲注.SQL注入   风险:可能会查看.修改或删除数据库条目和表.   原因:未对用户输入正确执行危险字符清理.   固定值:查看危险字符注入的可能解决方案. 2. pom.xml添加依赖 ...

  5. SpringBoot学习9:springboot整合thymeleaf

    1.创建maven项目,添加项目所需依赖 <!--springboot项目依赖的父项目--> <parent> <groupId>org.springframewo ...

  6. SpringBoot: 9.整合thymeleaf(转)

    1.创建maven项目,添加项目所需依赖 <!--springboot项目依赖的父项目--> <parent> <groupId>org.springframewo ...

  7. 【Springboot】Springboot整合Thymeleaf模板引擎

    Thymeleaf Thymeleaf是跟Velocity.FreeMarker类似的模板引擎,它可以完全替代JSP,相较与其他的模板引擎,它主要有以下几个特点: 1. Thymeleaf在有网络和无 ...

  8. SpringBoot系列——Thymeleaf模板

    前言 thymeleaf是springboot官方推荐使用的java模板引擎,在springboot的参考指南里的第28.1.10 Template Engines中介绍并推荐使用thymeleaf, ...

  9. java框架之SpringBoot(4)-资源映射&thymeleaf

    资源映射 静态资源映射 查看 SpringMVC 的自动配置类,里面有一个配置静态资源映射的方法: @Override public void addResourceHandlers(Resource ...

随机推荐

  1. ubuntu 使用cron设置定时启动任务

    介绍 cron,是一个Linux定时执行工具,可以在无需人工干预的情况下运行作业. 在Ubuntu server 下,cron是被默认安装并启动的:如果没有启动,自行设置并启动(chkconfig\s ...

  2. 关于Ble通信库BluetoothKit的使用 以及可能出现的问题分析

    首先,这个库是用于BLE(低功耗蓝牙)通信的,地址:https://github.com/dingjikerbo/BluetoothKit 当然,也可以选择根据andorid提供的底层接口自己完成这部 ...

  3. 1458 Common Subsequence

    最简单的LIS; 设字符串为 a = acc  b = cc 则dp数组为 0 0 1 1 1 2 b[0] = a[1], b[1] = a[1] 防止这里算两个 要清楚的是 怎么不重复计算 也就是 ...

  4. L2-013. 红色警报(并查集)*

    L2-013. 红色警报 参考博客 #include <cstdio> #include <algorithm> #include <iostream> #incl ...

  5. linux 查看当前系统版本号

    为避免现场未能完全安装系统,使用yum 安装版本需一致 第一种方法: [root@sky9896sky]# lsb_release -a bash:lsb_release: command not f ...

  6. ubuntu16.04+caffe+GPU+cuda+cudnn安装教程

    步骤简述: 1.安装GPU驱动(系统适配,不采取手动安装的方式) 2.安装依赖(cuda依赖库,caffe依赖) 3.安装cuda 4.安装cudnn(只是复制文件加链接,不需要编译安装的过程) 5. ...

  7. net core 解除上传大附件的限制

    1.对于使用自带服务器kernal的情况下,只需要在对应的action上添加属性 DisableRequestSizeLimit [HttpPost] [DisableRequestSizeLimit ...

  8. 如何将项目连接数据库(连接mysql)

    首先需要在项目中加入这一串代码: //加载驱动类 连接数据库有多种方式 比如:jdbc 桥接 Connection con=null; try { Class.forName("com.my ...

  9. 访问器 & 修改器

    访问器 model /** * 定义一个访问器 当 Eloquent 尝试获取 title 的值时,将会自动调用此访问器(查詢時自動調用) * @author jackie <2019.02.1 ...

  10. php正则判断是否同时有数字和字母

    1.php正则判断是否同时有数字和字母$subject = 'qq2';var_dump(preg_match('/^(?![0-9]+$)(?![a-zA-Z]+$)/', $subject)); ...