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. setfacl语法

    1.setfacl的用途setfacl命令可以用来细分linux下的文件权限. chmod命令可以把文件权限分为u,g,o三个组,而setfacl可以对每一个文件或目录设置更精确的文件权限. 换句话说 ...

  2. 关于attibutedText输出中文字符后的英文和数字进行分开解析的问题

    上面的图应该很清楚 具体这个attibutedText 是做什么的就不说了 ,最初我查了资料发现有人和我一样的输出,把一个字符串的中英文分开打印出来是iOS关于UItextVIew和UIlabel的差 ...

  3. 神州数码广域网Frame-Relay封装配置(即帧中继)

    实验要求:了解帧中继的配置方法 拓扑如下 R1 enable 进入特权模式 config 进入全局模式 hostname R1 修改名称 interface s0/1 进入端口 ip address ...

  4. AWS Redshift typical error and potential root cause:

    Full join issue: When use full join, the below join condition should not occur: 1, OR statement2, an ...

  5. Angular4.0引入第三方框架,eg: bootstrap、jquery

    最近学习angular4.0,在练习是需要使用jquery和bootstrap.但是查阅了,大多数都是angular2的方法,或者是angular4.0的方法但是不准确.花了一些时间终于捣腾出来了,把 ...

  6. 服务器-华为RH5885 V3-安装Windows Server 2008R2后设备管理器中存在大量的感叹号,并且无法识别网络适配器,没有网卡

    问题描述:用引导盘安装Windows Server 2008R2后,出现如题的情况. 根源:驱动未安装. 解决方法: 1.下载驱动:https://support.huawei.com/enterpr ...

  7. torchvision里densenet代码分析

    #densenet原文地址 https://arxiv.org/abs/1608.06993 #densenet介绍 https://blog.csdn.net/zchang81/article/de ...

  8. windows openssh 设置root 目录

    默认windows openssh 服务的root 目录是用户账户所在的目录(一般是administrator),但是我们可以通过修改sshd_config 重新修改路径 可选的修改方式 直接修改ss ...

  9. Git 2.x 中git push时遇到 push.default 警告的解决方法

    近在学习使用 git&GitHub,然后今天遇到了一个问题.在执行 git add 和 git commit 操作之后,再进行 git push 操作,出现了如下提示: $ git push ...

  10. 黄聪:如何扩展Chrome DevTools来获取页面请求

    1. Chrome DevTools Extension 熟悉React的同学,可能对React Developer Tools并不陌生,     刚看到的时候,我也觉得很神奇, 因为React De ...