SpringBoot中使用Thymeleaf模板
1、引入pom依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2、设置thymeleaf版本,版本3检查html标签可以没有闭合结束符
<properties>
<thymeleaf.version>3.0..RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.0.</thymeleaf-layout-dialect.version>
</properties>
3、配置文件设置thymeleaf属性
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-
spring.thymeleaf.content-type=text/html
spring.thymeleaf.mode=HTML5
4、在resources/templates新建index.html文件
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Hello World!</title>
</head>
<body>
<h1 th:inline="text">Hello</h1>
<p th:text="${hello}"></p>
</body>
</html>
5、编写controller
@RequestMapping
@Controller
public class IndexController { @GetMapping("/helloHtml")
public String testHelloHtml(Model model){
model.addAttribute("hello", "你好");
return "index";
}
}
SpringBoot中使用Thymeleaf模板的更多相关文章
- 在Spring MVC和Spring Boot中使用thymeleaf模板
Spring MVC: POM: <!-- thymeleaf模板 --> <!-- https://mvnrepository.com/artifact/org.thymeleaf ...
- 7 — 简单了解springboot中的thymeleaf
1.官网学习地址 https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html 2.什么是thymeleaf? 一张图看明白: 解读: ...
- springboot 中的 thymeleaf 页面进阶小知识
我们做好了登录页,那设计一个场景吧,比如我们登录后跳转到公司主页,想从公司主页再跳转到员工列表页: 这样的场景我们该如何实现,首先要知道一些基础知识,就是SpringBoot的一些关于请求的架构知识: ...
- springboot 中使用thymeleaf
Spring Boot支持FreeMarker.Groovy.Thymeleaf和Mustache四种模板解析引擎,官方推荐使用Thymeleaf. spring-boot-starter-thyme ...
- 最简单的 springboot 发送邮件,使用thymeleaf模板
1,导入需要的包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId&g ...
- SpringBoot中的thymeleaf引擎报错
关于:thymeleaf报错: An error happened during template parsing (template: "class path resource [temp ...
- SpringBoot 之Thymeleaf模板.
一.前言 Thymeleaf 的出现是为了取代 JSP,虽然 JSP 存在了很长时间,并在 Java Web 开发中无处不在,但是它也存在一些缺陷: 1.JSP 最明显的问题在于它看起来像HTML或X ...
- Spring Boot2(五):使用Spring Boot结合Thymeleaf模板引擎使用总结
一.Thymeleaf概述 一般来说,常用的模板引擎有JSP.Velocity.Freemarker.Thymeleaf . SpringBoot推荐的 Thymeleaf – 语法更简单,功能更强大 ...
- springboot 引入 thymeleaf 模板
第一步pom中: <!-- 引入 thymeleaf 模板依赖 --> <dependency> <groupId>org.springframework.boot ...
随机推荐
- [Javascript] Working with Static Properties on a Class
Classes are syntactic sugar over functions and functions are also referred to as "callable" ...
- Longest Common Substring SPOJ - LCS (后缀自动机)
Longest Common Substring \[ Time Limit: 294ms \quad Memory Limit: 1572864 kB \] 题意 给出两个串,求两个串的最长公共连续 ...
- Cookie实现购物车功能
这里的购物车暂时存放书,后期把参数改成Object,把方法抽取成接口,只要实现了接口的Object类都可以放进购物项,这样就实现了购物任何物品 使用购物项因为一个购物项可以包含某种商品的数量,总价等, ...
- 网络命令——write、wall、ping、ifconfig、mail
1.write命令: 前提:用户必须在线: (1)向zhb用户发送信息: (2)用户收到信息: CTRL+D结束会话. 2.wall(发送广播信息,即给在线的所有用户发送信息) 管理员发送消息(自己可 ...
- Redis之eval+lua实现初步
目录 目录 1 1. 前言 1 2. 执行方式 1 3. 执行过程 3 4. 使用原则 3 1. 前言 Redis的实现保证eval的执行是原子的,即使eval执行的lua超时,Redis也不会自动终 ...
- 模拟测试20191017~18 lrd Day1& Day2
$Day1:$ $T1:位运算$ 从低位到高位分类讨论就好了 记得判$inf$ $T2:集合论$ 考场上差点就打线段树了 用一个数组维护,同时用一个变量代表当前总体$+$&&$-$的值 ...
- mac下 Eclipse代码自动补齐 设置
Eclipse -> Perferences -> Java -> Editor -> Content Assist如下图. 将auto activation triggers ...
- maven 工具
maven 工具 1.打包:mvn clean package 2.打包并安装到本地仓库:mvn clean install 3.利用maven下载源代码:mvn dependency:sources ...
- Mybatis报错:org.apache.ibatis.builder.IncompleteElementException
org.apache.ibatis.builder.IncompleteElementException: Could not find result map java.lang.Integer遇到这 ...
- iOS逆向必备绝技之ipa重签名
一.重签名准备工作: 找到开发者证书和配置文件: 列出所有开发者证书文件: security find-identity -p codesigning -v 找一个开发环境配置文件生成entitlem ...