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. My IELTS result has come out 我的雅思成绩出来了

    Thanks to god, I finally get a score of 6.5, although my socres of  listening  and writing are only ...

  2. WCF分布式服务2-服务配置部署

    上图整理了服务配置过程中所用到的基本的元素,大致的步骤: 1. 主要是首先要在调用服务的程序集中添加服务的一个引用. 2.  然后添加一个service并指定服务的名称.终结点. 在添加一个servi ...

  3. 剑指Offer 50. 数组中重复的数字 (数组)

    题目描述 在一个长度为n的数组里的所有数字都在0到n-1的范围内. 数组中某些数字是重复的,但不知道有几个数字是重复的.也不知道每个数字重复几次.请找出数组中任意一个重复的数字. 例如,如果输入长度为 ...

  4. 周强 201771010141 《面向对象程序设计(java)》第七周学习总结

    实验目的与要求 (1)进一步理解4个成员访问权限修饰符的用途: (2)掌握Object类的常用API用法: (3)掌握ArrayList类用法与常用API: (4)掌握枚举类使用方法: (5)结合本章 ...

  5. HttpURLConnection与HttpClient浅析

    转自:https://blog.csdn.net/u012838207/article/details/82867701 HttpURLConnection与HttpClient浅析 1. GET请求 ...

  6. springboot打war包后部署到tomcat后访问返回404错误

    springboot打war包后部署到tomcat后访问返回404错误 1.正常情况下,修改打包方式为war <packaging>war</packaging> 2.启动类继 ...

  7. 如何用Python写一个每分每时每天的定时程序

    1.计算生日是星期几 当你女朋友要过生日了,你肯定要定找家饭店订个餐庆祝一下,餐馆工作日会空一些,周末位置不好定,要是能知道她的生日是星期几就好了,下面这个程序就能搞定~~ 比如girl friend ...

  8. spring cloud/spring boot同时支持http和https访问

    l老规矩为大家祭出原帖:https://www.cnblogs.com/lianggp/p/8136540.html  不再转述

  9. Python搭建环境

    小白开启Python之门啦啦啦!!!!! 学习任何一种语言,第一步就是环境的搭建,小白python之旅开始啦!!!加油加油,抬头挺胸齐步走~~~ 目前大家开发系统主要是,windows.Mac OS ...

  10. ie 浏览器缓存问题

    Get请求在IE会存在缓存问题,最直接的办法  改成Post请求解决