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 ...
随机推荐
- 【go语言实现服务器接收http请求以及出现泄漏时的解决方案】
一.关于基础的程序的实现 刚开始的时候程序是这样实现的: // Hello package main import ( "database/sql" "fmt" ...
- WEB框架之Django实现分页功能
一 Paginator分页器 1 首先在数据库中生成大量数据 def index(request) book_list = [] for i in rang(1000) book = Book(tit ...
- 使用PHP来简单的创建一个RPC服务
RPC全称为Remote Procedure Call,翻译过来为"远程过程调用".主要应用于不同的系统之间的远程通信和相互调用. 比如有两个系统,一个是PHP写的,一个是JAVA ...
- java命令行调用本地文件协议hikvideoclient://
最近在做一个视频项目,项目中需要通过调用海康本地协议打开视频播放器,起初尝试通过Process/ProcessBuilder无解,因为这个是调用本地应用程序的. 我要调用的是本地伪协议,最终通过一些研 ...
- thymeleaf 格式化时间
运用Thymeleaf模板后,前台的时间显示发生变化,和数据库不一致 HTML页面中格式如下: <td th:text="${fleeceRecord.cashmereDate}&qu ...
- 开启Windows文件共享必须开启的两个服务
开启Windows文件共享必须开启的两个服务分别是: 1.Server服务. 2.Workstation服务. 如果文件共享丢失,可以去首先去查看这两个服务是否停止,如果停止,请启动或者重启.
- Mac Terminal
一.简介 二.实用 1)update-apps-using-terminal-mac https://www.maketecheasier.com/update-apps-using-termin ...
- Linux硬件相关
1)查看设备号/厂商号 http://blog.csdn.net/styshoo/article/details/51203881 二.硬件厂商 1)瑞传科技股份有限公司 https://www. ...
- 11.Mysql视图
11.视图11.1 什么是视图 视图view是一张虚拟表,它不存储数据,数据仍在表里,视图由一条查询表的select语句创建,视图只存储select语句. 可以将复杂的查询语句封装成视图,用户可以从视 ...
- 关于ip包长度
http://blog.csdn.net/naturebe/article/details/6712153 这篇文章总结的不错,转自:http://hi.baidu.com/to_wait/blog/ ...