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 整合的更多相关文章

  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. 随机数、方法重载和System.out.println()的理解

    1.编写一个方法,使用以上算法生成指定数目(比如1000个)的随机数. package testradom; public class testradom { public static void m ...

  2. Netty---入门程序,搭建Websocket 服务器

    Netty 常用的场景: 1.充当HTTP 服务器,但Netty 并没有遵循servlet 的标准,反而实现了自己的一套标准进行Http 服务: 2,RPC 远程调用,在分布式系统中常用的框架 3.S ...

  3. golang 通过fsnotify监控文件,并通过文件变化重启程序

    一.下载我们需要的包 > go get github.com/fsnotify/fsnotify 二.使用fsnotify监控文件 package main; import ( "gi ...

  4. golang语言中sync/atomic包的学习与使用

    package main; import ( "sync/atomic" "fmt" "sync" ) //atomic包提供了底层的原子级 ...

  5. jsp获取ip使用request.getRemoteAddr返回0:0:0:0:0:0:0:1

    JAVA Web开发过程中,很多场景下需要获取访问终端的IP,对应方法getRemoteAddr.例如调试过程中本地回环ip地址是127.0.0.1,忽然有一天返回 0:0:0:0:0:0:0:1,这 ...

  6. Oracle性能优化4-索引

    Oracle优化可以分为通过改写sql优化和不改写sql优化不改写sql优化一般通过index来实现 在Oracle数据库中,索引按照索引机制的不同,可以分为三种. 1. B-Tree索引 B-Tre ...

  7. Java开发MIS系统需要的技术及其作用

    1.后台框架部分,常用spring.struts2(Struts2框架,提供了一种基于MVC体系结构的工程序的开发方法,具有组件模块化.灵活性和重用性等优点,使基于MVC模式的程序结构更加清晰,同时也 ...

  8. AsyncTask的缺陷

    导语:在开发Android应用的过程中,我们需要时刻注意保障应用的稳定性和界面响应性,因为不稳定或者响应速度慢的应用将会给用户带来非常差的交互体验.在越来越讲究用户体验的大环境下,用户也许会因为应用的 ...

  9. 团队作业之Rookie also want to fly

    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 在时代的浪潮下,单人编程,结对编程已经无法满 ...

  10. python实现文件下载图片视频

    最近在学习爬虫,在爬取网站时很多时候是需要将图片或视频下载到本地 今天就来说说如何使用urllib将图片保存到本地 以下代码均为win7  python3.6.* 方法一(使用下载函数保存) from ...