Thymeleaf 入门
基本项目结构:

Thymeleaf配置:
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/static/
spring.thymeleaf.suffix=.html
spring默认的模板映射路径是:src/main/resources/templates
ftl路径的hello.html:
<!DOCTYPE html>
<html lang="zh-CN"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"> <head>
<title>helloWorld</title>
</head> <body>
<h1>Hello : <b th:text="${name}">姓名</b></h1>
</body>
</html>
TestController:
package com.eshore.ismp.web; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; @Controller
public class TestController {
@RequestMapping(value = "test", method = RequestMethod.GET)
public String test(Model model) {
model.addAttribute("name", "MERCY");
return "/ftl/hello";
} }
运行结果:

要注意的点:
spring.thymeleaf.cache要设置为true,以方便开发及时看到页面刷新
springboot直接引入:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
非springboot项目引入:
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>2.1.4</version>
</dependency>
LEGACYHTML5属性值需要搭配一个额外的库NekoHTML才可用。主要作用是设置Thymeleaf格式检查没这么严格,默认属性值是HTML5
Thymeleaf 入门的更多相关文章
- thymeleaf入门
controller层添加实体 html <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> ...
- Thymeleaf入门到吃灰
Thymeleaf 官网部分翻译:反正就是各种好 Thymeleaf是用来开发Web和独立环境项目的服务器端的Java模版引擎 Spring官方支持的服务的渲染模板中,并不包含jsp.而是Thymel ...
- Thymeleaf入门入门入门入门入门入门入门入门入门入门入门
Thymeleaf 官网部分翻译:反正就是各种好 Thymeleaf是用来开发Web和独立环境项目的服务器端的Java模版引擎 Spring官方支持的服务的渲染模板中,并不包含jsp.而是Thymel ...
- Thymeleaf入门基础
一.简介 1.thymeleaf优点 ①是一个支持html原型的自然引擎,它在html标签增加额外的属性来达到模板+数据的展示方式,由于浏览器解释html时,忽略未定义的标签属性,因此thymelea ...
- Thymeleaf入门(一)——入门与基本概述
一.概述 1.是什么 简单说, Thymeleaf 是一个跟 Velocity.FreeMarker 类似的模板引擎,它可以完全替代 JSP . 2.feature 1.Thymeleaf 在有网络和 ...
- 学习小片段——thymeleaf入门
1: 概述 thymeleaf是一个跟 Velocity.FreeMarker 类似的模板引擎,和以前学的jsp相近,但性能上无疑是比jsp好. 参考文档官方文档:https://www.thymel ...
- thymeleaf入门和学习
springboot框架不推荐使用jsp,一方面是兼容性的技术问题,一方面也是其前后端整合在一起,很难适合当下大规模的网站开发环境.HTML只是一种标记语言,并不具有获取model中数据的功能,所以视 ...
- Thymeleaf入门与基础语法
1.简介 Thymeleaf是用来开发Web和独立环境项目的现代服务器端Java模板引擎. Thymeleaf的主要目标是为您的开发工作流程带来优雅的自然模板 - HTML.可以在直接浏览器中正确显示 ...
- Thymeleaf入门——入门与基本概述
https://www.cnblogs.com/jiangbei/p/8462294.html 一.概述 1.是什么 简单说, Thymeleaf 是一个跟 Velocity.FreeMarker 类 ...
随机推荐
- 小波变换——子带编码,Subband Coding
离散小波变换.多级信号分解,多分辨率分析. Multiresolution Analysis(MRA.多分辨率分析) 子带编码(Subband Coding) 简称SBC. 一种以信号频谱为依据的编码 ...
- linux环境中,ssh登录报错,Permission denied, please try again.
问题描述: 今天早上一个同事反应一个问题,通过ssh登录一台测试机的时候,发现两个账号,都是普通账号,一个账号能够登录, 另外一个账号无法登录.问他之前有做过什么变更吗,提到的就是之前有升级过open ...
- logback.xml常用配置详解
<?xml version="1.0" encoding="UTF-8"?><configuration debug="false& ...
- Android基础部分再学习---activity的状态保存
主要是bundle 这个參数 參考地址:http://blog.csdn.net/lonelyroamer/article/details/18715975 学习Activity的生命周期,我们知 ...
- mysql性能监控qps,tps,iops
qps 每秒处理的查询数tps 每秒处理的事务数IOPS,每秒磁盘进行的I/O操作次数 给个方法或者思路,用啥工具或者命令,如何看,值是多少属于正常范围之内呢? Information from we ...
- 查看python中已安装的包有哪些
新版本执行:pip list 老版本执行:pip freeze
- RF-获取上个月份
验证1: case ${NowDate} set variable 20170103 ${year} set variable ${NowDate[0:4]} ${month} set variabl ...
- [Python] Python 之 function, unbound method 和 bound method
首先看一下以下示例.(Python 2.7) #!/usr/bin/env python # -*- coding: utf-8 -*- class C(object): def foo(self): ...
- VMware按装ISO
破解码 vmware12 5A02H-AU243-TZJ49-GTC7K-3C61N vmware14CG54H-D8D0H-H8DHY-C6X7X-N2KG6 创建虚拟机 也可以选第三个直接选择Ce ...
- C语言char*字符串数组和unsigned char[]数组的相互转换
#include <iostream> #include <string> using namespace std; void convertUnCharToStr(char* ...