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. 【校招面试 之 网络】第3题 HTTP请求行、请求头、请求体详解

    1.HTTP请求报文解剖 HTTP请求报文由3部分组成(请求行+请求头+请求体): 下面是一个实际的请求报文: ①是请求方法,GET和POST是最常见的HTTP方法,除此以外还包括DELETE.HEA ...

  2. 纯java+maven+sqlserver使用mybatis

    第一部分:基本实现 @参考文章,在此基础上略作修改 1,新建maven项目JavaMybatis导入依赖 <dependencies> <dependency> <gro ...

  3. Linux日志文件分割

    经常有这样的情况,日志文件或者数据文件会变得很庞大,那么每次对这些目标文件的访问或者修改就会变得极其耗时.因而引发一些性能问题,但是如果对这些目标文件进行分割,限定其大小,那么每次的访问或者修改就会变 ...

  4. mysql修改表引擎Engine

    修改my.ini,在[mysqld]下加上default-storage-engine=INNODB 其中红色字体部分是要指定的引擎名称.用sql语句修改已经建成表的引擎:alter table ta ...

  5. mysql导入慢解决方法

    [mysqldump]max_allowed_packet = 512M [mysqld] interactive_timeout = 120 innodb_change_buffering=alli ...

  6. 访问WebServcie遇到配额不足的时候,请增加配额

    常常遇到的报错: 1.错误一: Error in deserializing body of reply message for operation 'GetArticleInfo'.,StackTr ...

  7. Liunx Mkdir

    linux mkdir命令: 创建目录 介绍:该命令创建指定的目录名,要求创建目录的用户在当前目录中具有写权限,并且指定的目录名不能是当前目录中已有的目录1语法: mkdir [-m] [-p] 目录 ...

  8. 虚拟机安装oracle重新启动后oracle em起不来 ORA-01034: ORACLE not available

    (转)http://zhidao.baidu.com/link?url=hM74OA-oWNGGx6RcDaGBwB8Hs0bAnVeKxpC6gpoCGtIGJZ8duYcC-YJ1WNCF7lkP ...

  9. laravel 服务提供者介绍和使用

    #安装传送门 安装composer,以及通过composer安装laravel #讲解使用 服务提供者这个具体表现都是围绕着依赖注入 在根目录config/app.php的providers中的数组中 ...

  10. linux执行系统命令时挂起

    现象:使用mock构建时出现挂起现象 1.排除内存不足和构建工作空间所在磁盘分区不足情形: 2.执行任何系统命令异常卡顿 原因: 1.系统根分区空间严重不足: 解决办法: 清理根分区无用文件 1> ...