Thymeleaf是一个Java模板引擎开发库,可以处理和生成HTML、XML、JavaScript、CSS和文本,在Web和非Web环境下都可以正常工作。

Thymeleaf可以跟Spring boot很好的集成。

整合步骤

1.修改pom.xml

增加下面代码片段:

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-thymeleaf</artifactId>
  4. </dependency>

2.修改 application.yml 配置

  1. spring:
  2. thymeleaf:
  3. mode: HTML5
  4. encoding: utf-8
  5. content-type: text/html
  6. classpath: /templates/*.html

模版位置在:

resources/templates 目录下面

3.编写模版文件

  1. <!DOCTYPE html>
  2. <html xmlns:th="http://www.thymeleaf.org">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>Insert title here</title>
  6. <link th:href="@{/my.css}" rel="stylesheet" />
  7. </head>
  8. <body>
  9. <h2>用户列表</h2>
  10. <div>
  11. <span th:text="${user.name}"></span>-
  12. <span th:text="${user.address}"></span>
  13. </div>
  14. </body>
  15. </html>

使用样式表文件:

样式表文件目录在:

4.控制器代码

  1. @RequestMapping("/userDetail")
  2. public ModelAndView userDetail() {
  3. User user=new User();
  4. user.setName(this.name);
  5. user.setAddress(this.address);
  6. ModelAndView mv=new ModelAndView();
  7. mv.setViewName("/sys/user");
  8. mv.addObject("user", user);
  9. return mv;
  10. }

5.效果

springboot Thymeleaf 整合的更多相关文章

  1. SpringBoot 同时整合thymeleaf html、vue html和jsp

    问题描述 SpringBoot如何同时访问html和jsp SpringBoot访问html页面可以,访问jsp页面报错 SpringBoot如何同时整合thymeleaf html.vue html ...

  2. thymeleaf第二篇:理解原理并为后面springboot进行整合进行铺垫

    官方入门之从虚拟商店理解thymeleaf 参考文档: 简单使用Thymeleaf API渲染模板生成静态页面 邮件通知改造之Thymeleaf渲染模板生成静态页面--看懂会帮助理解springboo ...

  3. org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method service() cannot be found on com.my.blog.springboot.thymeleaf.util.MethodTest type

    前言 本文中提到的解决方案,源码地址在:springboot-thymeleaf,希望可以帮你解决问题. 至于为什么已经写了一篇文章thymeleaf模板引擎调用java类中的方法,又多此一举的单独整 ...

  4. SpringBoot+thymeleaf+security+vue搭建后台框架 基础篇(一)

    刚刚接触SpringBoot,说说踩过的坑,主要的还是要记录下来,供以后反省反省! 今天主要讲讲 thymeleaf+security 的搭建,SpringBoot的项目搭建应该比较简单,这里就不多说 ...

  5. SpringBoot:整合Shiro

    目录 1.Shiro简介 1.1.什么是Shiro? 1.2.有哪些功能 1.3.Shiro架构(外部) 1.4.Shiro架构(内部) 2.HelloWorld 3.Shiro整合Spring Bo ...

  6. SpringBoot:整合SpringSecurity

    目录 SpringSecurity(安全) 搭建环境 使用 用户认证和授权 注销及权限控制 记住我及登录页面定制 SpringBoot 整合 SpringSecurity: 用户认证和授权.注销及权限 ...

  7. springboot+layui 整合百度富文本编辑器ueditor入门使用教程(踩过的坑)

    springboot+layui 整合百度富文本编辑器ueditor入门使用教程(踩过的坑) 写在前面: ​ 富文本编辑器,Multi-function Text Editor, 简称 MTE, 是一 ...

  8. SpringBoot+AOP整合

    SpringBoot+AOP整合 https://blog.csdn.net/lmb55/article/details/82470388 https://www.cnblogs.com/onlyma ...

  9. SpringBoot+Redis整合

    SpringBoot+Redis整合 1.在pom.xml添加Redis依赖 <!--整合Redis--> <dependency> <groupId>org.sp ...

随机推荐

  1. PLSQL连接Oracle数据库问题及详解

    一.Oracle数据库安装步骤参考:https://jingyan.baidu.com/article/363872eccfb9266e4aa16f5d.html 二.Oracle客户端安装:http ...

  2. 脚手架搭建vue框架

    一. node安装 1)如果不确定自己是否安装了node,可以在命令行工具内执行: node -v  (检查一下 版本): 2)如果 执行结果显示: xx 不是内部命令,说明你还没有安装node , ...

  3. 【校招面试 之 网络】第2题 TCP的可靠传输、流量控制、滑动窗口

    1.可靠传输 (1)三次握手 TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接: (1)第一次握手:建立连接时,客户端A发送SYN包(SYN=j)到服务器B,并进入SYN_S ...

  4. stark组件之批量操作【模仿Django的admin】

    一.先看下django的admin是如何实现批量操作 首先在配置类中定义一个函数 然后我们为这个函数对象设置一个属性,这个属性主要用来显示在select标签中显示的文本内容 最后把函数对象放到一个ac ...

  5. LRU缓存原理

    LRU(Least Recently Used)  LRU是近期最少使用的算法,它的核心思想是当缓存满时,会优先淘汰那些近期最少使用的缓存对象. 采用LRU算法的缓存有两种:LrhCache和DisL ...

  6. 微信小程序 错误记录

    1.报错this.getUserInfo(this.setData) is not a function;at pages/index/index onShow function;at api req ...

  7. centos7下apache2.4反向代理

    apache安装目录在/data/apache24,这里就不介绍apache的安装了. 一.反向代理配置 在/data/apache24/conf/extra下创建htttpd-proxy.conf文 ...

  8. SQL Server 数据库备份还原常用SQL语句及注意

    1.备份数据库 backup database db_name to disk='d:\db_name.bak' with format --通过使用with format可以做到覆盖任何现有的备份和 ...

  9. find和find_if,value_type

    find算法:返回 [first,end)中第一个值等于value元素的位置 线性复杂度:最多比较次数:元素的总个数 find函数的最后一个参数,必须是string,float,char,double ...

  10. 使用/\_ 打印正三角形 C/C++

    输入size,level,使用/\_,打印正三角形 #include<stdio.h> int main() { int level, size; printf("Enter l ...