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 ...
随机推荐
- Edge Beta 进入无痕模式 快捷方式
“浏览器路径” -InPrivate 在快捷方式的路径后加 -InPrivate 就可以了
- js 实现页面点击按钮复制内容
前言: 我们平时在页面中是按照长按来实现复制相关的内容,那么怎么用js实现点击按钮实现复制相关的内容呢?请看如下方法: 实现步骤: 1.引入相关的js(ClipboardJS插件) <scrip ...
- golang 配置goproxy 几个可选的地址
对于golang 语言的开发,对于国内来说有点被动,需要想各种方法,一般的解决方法如下: 使用代理工具(翻墙) 配置goproxy 目前发现的几个不错的goproxy 阿里云 配置如下: expo ...
- genie 来自netflix 的分布式大数据调度服务
Genie是Netflix开发的联合作业编排引擎.Genie提供REST-ful API来运行各种大数据工作,如Hadoop,Pig,Hive,Spark,Presto,Sqoop等.它还提供用于管理 ...
- 用于C# 的异步,持久的键值存储 Akavache 使用
Akavache是一个异步的,持久的(即写入磁盘)键值存储,用于在C#中编写桌面和移动应用程序,基于SQLite3.Akavache非常适合存储重要数据(即用户设置)以及过期的缓存本地数据. 开源 ...
- python3 安装 pillow报错
前言 最近要使用pillow库, 来训练验证码模型, 但是死活都安装不上 环境 docker中安装, python3 尝试安装 pip install pillow easy_install Pill ...
- SVN cornerstone Commit\Update 提示xxx is already Locked解决方法
点击菜单栏“working copy” 点“clean”: 或者,如下图: 右击,点击“clean”,问题解决.
- 【Spring Boot】内嵌容器
Spring Boot内嵌容器支持Tomcat.Jetty.Undertow. tomcat容器 spring boot 的web应用开发必须使用spring-boot-starter-web,其默认 ...
- R语言中查询帮助
可以尝试下面的几种方式 help(lapply,package=,....)?lapply??lapplyhelp.search('lapply')apropos('norm') #函数名记不全时用? ...
- Mysql与Postgresql常用命令比较
PostgreSQL MySQL 服务启动:1)#service postgresql start2)#/etc/init.d/postgresql start3)#su – postgresql$p ...