美文网首页java学习笔记整理
Spring Boot框架 + Thymeleaf模板引擎

Spring Boot框架 + Thymeleaf模板引擎

作者: _借东西的小人 | 来源:发表于2019-08-20 14:29 被阅读0次

引入依赖

pom.xml中引入模板

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

application.properties文件中添加Thymeleaf配置

  • 模板的模式,支持HTML,XML,TEXT,JAVASCRIPT等
    spring.thymeleaf.mode=HTML5
  • 编码,可不用配置
    spring.thymeleaf.encoding=UTF-8
  • 内容类别,可不用配置
    spring.thymeleaf.content-type=text/html
  • 开发配置为false,避免修改模板还要重启服务器
    spring.thymeleaf.cache=false
  • 配置模板路径,默认是templates,可以不用配置
    spring.thymeleaf.prefix=classpath:/templates/
注意:Thymeleaf模板引擎默认会读取springboot项目资源文件夹的resource下的templates目录,这个目录是用来存放HTML文件的.如果我们添加了Thymeleaf依赖,而没有进行任何配置,或者添加默认目录,启动时就会报错.
image.png image.png

相关文章

网友评论

    本文标题:Spring Boot框架 + Thymeleaf模板引擎

    本文链接:https://www.haomeiwen.com/subject/dugusctx.html