springboot Thymeleaf 整合
Thymeleaf是一个Java模板引擎开发库,可以处理和生成HTML、XML、JavaScript、CSS和文本,在Web和非Web环境下都可以正常工作。
Thymeleaf可以跟Spring boot很好的集成。
整合步骤
1.修改pom.xml
增加下面代码片段:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.修改 application.yml 配置
spring:
thymeleaf:
mode: HTML5
encoding: utf-8
content-type: text/html
classpath: /templates/*.html
模版位置在:
resources/templates 目录下面

3.编写模版文件
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8" />
<title>Insert title here</title>
<link th:href="@{/my.css}" rel="stylesheet" />
</head>
<body>
<h2>用户列表</h2>
<div>
<span th:text="${user.name}"></span>-
<span th:text="${user.address}"></span>
</div>
</body>
</html>
使用样式表文件:
样式表文件目录在:

4.控制器代码
@RequestMapping("/userDetail")
public ModelAndView userDetail() {
User user=new User();
user.setName(this.name);
user.setAddress(this.address);
ModelAndView mv=new ModelAndView();
mv.setViewName("/sys/user");
mv.addObject("user", user);
return mv;
}
5.效果

springboot Thymeleaf 整合的更多相关文章
- SpringBoot 同时整合thymeleaf html、vue html和jsp
问题描述 SpringBoot如何同时访问html和jsp SpringBoot访问html页面可以,访问jsp页面报错 SpringBoot如何同时整合thymeleaf html.vue html ...
- thymeleaf第二篇:理解原理并为后面springboot进行整合进行铺垫
官方入门之从虚拟商店理解thymeleaf 参考文档: 简单使用Thymeleaf API渲染模板生成静态页面 邮件通知改造之Thymeleaf渲染模板生成静态页面--看懂会帮助理解springboo ...
- 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类中的方法,又多此一举的单独整 ...
- SpringBoot+thymeleaf+security+vue搭建后台框架 基础篇(一)
刚刚接触SpringBoot,说说踩过的坑,主要的还是要记录下来,供以后反省反省! 今天主要讲讲 thymeleaf+security 的搭建,SpringBoot的项目搭建应该比较简单,这里就不多说 ...
- SpringBoot:整合Shiro
目录 1.Shiro简介 1.1.什么是Shiro? 1.2.有哪些功能 1.3.Shiro架构(外部) 1.4.Shiro架构(内部) 2.HelloWorld 3.Shiro整合Spring Bo ...
- SpringBoot:整合SpringSecurity
目录 SpringSecurity(安全) 搭建环境 使用 用户认证和授权 注销及权限控制 记住我及登录页面定制 SpringBoot 整合 SpringSecurity: 用户认证和授权.注销及权限 ...
- springboot+layui 整合百度富文本编辑器ueditor入门使用教程(踩过的坑)
springboot+layui 整合百度富文本编辑器ueditor入门使用教程(踩过的坑) 写在前面: 富文本编辑器,Multi-function Text Editor, 简称 MTE, 是一 ...
- SpringBoot+AOP整合
SpringBoot+AOP整合 https://blog.csdn.net/lmb55/article/details/82470388 https://www.cnblogs.com/onlyma ...
- SpringBoot+Redis整合
SpringBoot+Redis整合 1.在pom.xml添加Redis依赖 <!--整合Redis--> <dependency> <groupId>org.sp ...
随机推荐
- Mastering Unity 2D Game Development
Mastering Unity 2D Game Development will give your game development skills a boost and help you begi ...
- 使用mybatis-generator-core工具自动生成mybatis实体
我们可以使用mybatis-generator-core这个工具将数据库对象转换成mybatis对象,具体步骤如下. 1.mybatis-generator-core下载 下载地址:http://do ...
- JDK1.5 Excutor 与ThreadFactory
Excutor 源码解读: /** * An object that executes submitted {@link Runnable} tasks. This * interface provi ...
- js去除字符串空格(空白符)
使用js去除字符串内所带有空格,有以下三种方法: ( 1 ) replace正则匹配方法 去除字符串内所有的空格:str = str.replace(/\s*/g,""); 去除字 ...
- 使用独立的log4net.config文件配置log4net,将日志记录到Mysql数据库【原创】
开发环境: VS2013, Asp.Net MVC 4.0, .Net Framework 4.0, Log4net 1.2.13.0, Mysql.Data.dll,6.8.3.0 设置步骤: 1. ...
- Jmeter分布测试
一.负载机为Linux Linux上安装Jmeter 1.Windows中jmeter整个安装目录copy至Linux /usr/local/autodeploy目录 ps.使用winSCP工具cop ...
- SDK Manager 基础下载
双击SDK Manager打开Android SDK Manager. 全选以下几项 创建新项目 更改gradle的地址: 更改app的build.gradle: android { buildToo ...
- vs 调试 IE显示“无法显示该网页
在用VS2010调试网站的时候,突然页面不能正常显示了,IE显示“无法显示该网页”.症状一: IE地址栏里面显示的端口号和桌面任务栏右下角“ASP.NET Development Server”的端口 ...
- PAT 1087 有多少不同的值(20)(STL—set)
1087 有多少不同的值(20 分) 当自然数 n 依次取 1.2.3.--.N 时,算式 ⌊n/2⌋+⌊n/3⌋+⌊n/5⌋ 有多少个不同的值?(注:⌊x⌋ 为取整函数,表示不超过 x 的最大自然数 ...
- 常用的TCP Option
当前,TCP常用的Option如下所示———— Kind (Type) Length Name Reference 描述 & 用途 0 1 EOL RFC 793 选项列表结束 1 1 NOP ...