SpringBoot使用Thymeleaf模板
© 版权声明:本文为博主原创文章,转载请注明出处
Thymeleaf模板简介
Thymeleaf模板是一个现代化的服务端java模板引擎对于所有的web和独立环境
Thymeleaf的主要目标是为你的开发工作流程带来优雅自然的模板 ------ HTML能正确的显示在浏览器中,并且也可以作为静态原型工作,允许开发团队加强协作
在有Spring框架的模块,与您最喜爱的工具的集成为一体,并能插入自己的功能,Thymeleaf是理想的现代化的HTML5 Web开发JVM ------ 虽然它可以做的更多
摘自官网:http://www.thymeleaf.org/
也是SpringBoot推荐使用的模板
SpringBoot配置
1. application.yml配置(application.properties同样)
spring:thymeleaf:prefix: classpath:/templates/ # 必须以/结尾,否则报错找不到模板suffix: .htmlmode: HTML5encoding: UTF-8cache: false # 关闭缓存,即时刷新。上线后需改为trueservlet:content-type: text/html
2. 实现Controller
package com.imooc.controller;import com.imooc.pojo.User; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping;@Controller @RequestMapping("th") public class ThymeleafController {@GetMapping("/index")public String index(ModelMap map) {map.addAttribute("name", "thymeleaf-imooc");return "thymeleaf/index";}@GetMapping("/center")public String center() {return "thymeleaf/center/center";}@GetMapping("/test")public String test() {User user = new User();return "";}}
3. 创建Thymeleaf模板
3.1 index.html(位于 templates/thymeleaf/ 目录下)
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title></title> </head> <body>Thymeleaf模板引擎<h1 th:text="${name}">hello world</h1> </body> </html>
3.2 center.html(位于 templates/thymeleaf/center/ 目录下)
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title></title> </head> <body>Thymeleaf模板引擎<h1>center page</h1> </body> </html>
4. 启动SpringBoot项目,测试即可
参考:
https://www.imooc.com/video/16721
转载于:https://www.cnblogs.com/jinjiyese153/p/8566130.html
SpringBoot使用Thymeleaf模板相关推荐
- Springboot整合thymeleaf模板
Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...
- SpringBoot整合Thymeleaf模板引擎以及静态资源的访问
SpringBoot整合Thymeleaf模板引擎静态资源访问的配置 Thymeleaf是一个现代服务器端Java模板引擎,适用于Web和独立环境,能够处理HTML,XML,JavaScript,CS ...
- 玩转springboot:thymeleaf模板引擎入门程序
一.前言 常用的模板引擎有:JSP.Velocity.Freemarker.Thymeleaf 但是,Springboot默认是不支持JSP的,默认使用thymeleaf模板引擎.而且,语法更简单,功 ...
- 九、SpringBoot集成Thymeleaf模板引擎
Thymeleaf咋读!??? 呵呵,是不是一脸懵逼...哥用我的大学四级英文知识告诉你吧:[θaimlif]. 啥玩意?不会音标?...那你就这样叫它吧:"赛母李府",大部分中国 ...
- SpringBoot框架+Thymeleaf模板引擎实现发送HTML格式邮件(可带附件)
spring-boot-mail 项目结构 1.Maven工程依赖坐标 注意:SpringBoot版本需为2.x 若spring boot版本为1.x, <?xml version=" ...
- springboot使用thymeleaf模板引擎时出现org.xml.sax.SAXParseException的原因与解决办法
异常描述: 在springboot程序当中,使用thymeleaf作为视图的时候,跳转到页面上的时候,会出现org.xml.sax.SAXParseException的异常(SAX解析器解析xml文件 ...
- <12>springboot集成thymeleaf模板引擎
创建一个springboot工程,导入以下依赖 <dependencies><!--springboot框架web组件依赖--><dependency><gr ...
- Springboot 使用thymeleaf模板layout布局
使用layout布局前应该在pom文件中导入thymeleaf(dialect)依赖:如下 <properties><project.build.sourceEncoding> ...
- JavaWeb学习之路——SpringBoot 中thymeleaf模板用法(三)
thymeleaf模板用法 thymeleaf通过它特定的语法,对HTML的标记做渲染,能够访问后台的动态数据,实现静态html界面的动态化 1.添加架包 <!--引入动态模板-->< ...
最新文章
- mysql数据库连接jar_mysql数据库连接jar包
- Paddle网络结构中的层和模型
- 基于 OpenYurt EdgeX Foundry 的云边端一体化解决方案
- PHP空指针,PHP 5.3.7之前版本空指针引用拒绝服务漏洞
- 光流 | 基于光流的实时运动物体检测(MATLAB代码)
- Android 断点续传实现原理
- 电脑word在哪_怎么将图片转换成Word?学会这3种方法,轻松将图片转文字!
- kafka的分区策略(partition assignment strategy)
- SAP UI5 初学者教程之八 - 多语言的支持试读版
- 目前的计算机系统属于第三代电子计算机,计算机应用基础判断题
- jre6-java运行环境_Java运行环境(JRE8)64位 1.8.0.25
- 【华为云技术分享】智能诊断和优化,华为云DAS服务云DBA平台让您无忧运维
- (MATLAB中文乱码)UTF-8转GBK编码
- Caused by: java.lang.ClassNotFoundException: org.jaxen.JaxenException
- 720视频2码率够吗_两个人去丽江5000够吗,2人去云南旅游5天多少钱(超详细篇)...
- rebase操作使用方法
- java 父类构造_java 父类构造器
- Vue全家桶:Vuex
- TensorFlow性能分析调研
- 支持向量机(SVM)----超详细原理分析讲解