首先引入maven jar依赖

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>

接着在application.properties内配置 thymeleaf

#设置thymeleaf  注意:一定要在web后面添加一个 斜杠 /,否则找不到文件
spring.thymeleaf.prefix=classpath:/web/
spring.thymeleaf.suffix=.html
#设置thymeleaf不按照HTML5严格的检查标签
spring.thymeleaf.mode=LEGACYHTML5

模板默认还是放在templates文件夹下,这里我修改到web文件夹下面了

package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import com.example.demo.entity.Student; @Controller
@RequestMapping("/student/")
public class StudentController { @RequestMapping("show")
public String show(Model model) { Student stu = new Student();
stu.setId(1001);
stu.setName("小明");
model.addAttribute("student", stu); model.addAttribute("str", "this is spring boot freemarker");
return "show";
} }
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>thymeleaf</h1>
<h3 th:text="${str}">h3</h3>
id:<span th:text="${student.id}"></span><br>
name:<span th:text="${student.name}"></span>
</body>
</html>

最新文章

  1. from表单提交数组
  2. 51nod1185(wythoff+高精度)
  3. Intellij 打开就闪退或关闭
  4. touches, targetTouches, changedTouches 区别
  5. CentOS7 桌面的安装
  6. XML学习总结(一)——XML介绍
  7. what is php?
  8. C#: MessageBox
  9. Socket连接
  10. UVa 11178 (简单练习) Morley&#39;s Theorem
  11. 关于Struts2的客户端校验的FreeMarker template error!
  12. 【C语言】超大数乘法运算
  13. hadoop三个配置文件的参数含义说明core-site.xml,hdfs-site.xml,mapred-site.xml
  14. [51nod][cf468D]1558 树中的配对
  15. WdatePicker设置时间区间时,对开始时间和结束时间限制
  16. java中的Iterator与增强for循环的效率比较
  17. [php] in_array 判断问题(坑)
  18. 【NOIP2016】蚯蚓(队列,单调性)
  19. Swagger中配置了@ApiModelProperty的allowableValues属性但不显示的问题
  20. Linux-pthread如何设置线程的优先级

热门文章

  1. 阻塞赋值与非阻塞赋值(verilog篇)
  2. [ci]安装配置jenkins及其插件
  3. 142. Linked List Cycle II【easy】
  4. NGINX扩展
  5. tcp3握手,作用,syn攻击
  6. 当synchronized关键字和this关键字
  7. 各种排序算法C++
  8. JavaScript-4.5 事件大全,事件监听---ShinePans
  9. VMware虚拟机 Ubuntu 实用技巧 (1) -- 安装VMware Tool
  10. 第四篇:Elaticsearch 安装配置