本次学习如何使用thymeleaf以及相关语法
1、在上一章写的那样 引入jar包到maven工程

    <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2、同理配置yml

### springboot配置
spring:
##模板设置
thymeleaf:
prefix: classpath:/templates
suffix: .html
mode: LEGACYHTML5
encoding: utf-8
servlet:
content-type: text/html
cache: false

3、在需要引用thymeleaf添加引用头

<html xmlns:th="http://www.thymeleaf.org">

下面记录一下thymeleaf的模板语法 和jsp稍微有些出入 不过好在不需要修改文件类型 直接将html进行头部引用就可以使用
(1)标签引入路径或地址

<a th:href="@{http://www.baidu.com}"></a> //绝对路径进行访问
<script th:src="@{/}"></script>//相对路径进行访问
<link rel="stylesheet" th:href="@{css/base.css}">//默认访问static下的文件夹
<img th:src="@{}"/>//图片路径引用

(2)使用变量动态替换

<div th:text="hello ${roms}">hello world</div>

使用spring想也面传值roms:xxx即可在页面汇总替换${roms}进行内容修改
需要注意的是 th:text 会替换掉标签内的所有内容
(3)条件适用

//使用if进行判断是否为真
<div th:text="hello world" th:if=${flag != true}>Login</div>
//使用unless 表示除外
<div th:text="hello world" th:unless=${flag != true}>Login</div>

(4)循环的使用

  <table>
<tr th:each="list: ${list}">
<td th:text="${list.id}">1122334</td>
<td th:text="${plistod.name}">tony</td>
</tr>
</table>

(5)工具方法使用

//日期格式化
${#dates.format(date, 'yyyy/MMM/dd HH:mm')}
//当前时间
${#dates.createNow()}
//当前日期
${#dates.createToday()}

还有其他的工具类#Calendars,#numbers,#strings,#objects,#bools,#arrays,#lists,#sets,#maps,#aggregates,#messages,#ids
详细的api文档可以查看官网
http://www.thymeleaf.org/doc/...

springboot学习日志(二)-- thymeleaf学习的更多相关文章

  1. Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客

    ==他的博客应该不错,没有细看 Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客 http://blog.csdn.net/u012706811/article/det ...

  2. ROS2学习日志:QoS学习日志

    QoS学习日志 参考:ROS2API 及 https://index.ros.org/doc/ros2/Concepts/About-Quality-of-Service-Settings 1.概述 ...

  3. Spring Boot学习记录(二)–thymeleaf模板

    自从来公司后都没用过jsp当界面渲染了,因为前后端分离不是很好,反而模板引擎用的比较多,thymeleaf最大的优势后缀为html,就是只需要浏览器就可以展现页面了,还有就是thymeleaf可以很好 ...

  4. mybatis学习日志二

    一.动态sql语句 if语句 if+where语句 if+set语句 choose(when,otherwise)语句 trim语句 sql片段 foreach语句 总结 bean部分的User类代码 ...

  5. 《视觉SLAM十四讲》学习日志(二)——初识SLAM

    小萝卜机器人的例子: 就像这种机器人,它的下面有一组轮子,脑袋上有相机(眼睛),为了让它能够探索一个房间,它需要知道: 1.我在哪——定位 2.周围环境怎么样——建图 定位和建图可以理解成感知的 &q ...

  6. spring学习日志二

    一.spring依赖注入的方式 1.通过set方法来完成注入 <bean id="student" class="com.zhiyou100.xz.spring.S ...

  7. springmvc学习日志二

    一.当接受的参数为日期类型时 1.建立jsp页面,向Controller类传入参数 1.1当传入的参数为单个时 <body> <form action="user/toDa ...

  8. [jQuery学习系列二 ]2-JQuery学习二-数组操作

    前言 上一篇内容 已经对于Jquery 有了一些认识, 包括Jquery的选择器和DOM对象, 那么这一篇继续来看下Jquery中很实用的Jquery对于数组的操作. Jquery中对数组的操作大致有 ...

  9. Flask 学习篇二:学习Flask过程中的记录

    Flask学习笔记: GitHub上面的Flask实践项目 https://github.com/SilentCC/FlaskWeb 1.Application and Request Context ...

  10. WebGPU学习(二): 学习“绘制一个三角形”示例

    大家好,本文学习Chrome->webgl-samplers->helloTriangle示例. 准备Sample代码 克隆webgl-samplers Github Repo到本地. ( ...

随机推荐

  1. WAMP中的mysql设置密码

    为WAMP中的mysql设置密码密码 WAMP安装好后,mysql密码是为空的,那么要如何修改呢?其实很简单,通过几条指令就行了,下面我就一步步来操作. 1.首先,通过WAMP打开mysql控制台. ...

  2. PhpStorm配置Xdebug调试

    安装xdebug 去官网下载对应版本的xdebug扩展 XDEBUG EXTENSION FOR PHP | DOWNLOADS 如何选择正确版本 输出phpinfo()函数的内容 查看输出页面的网页 ...

  3. redis 无序集合 数据类型

    sadd  emptno 8000 sadd  emptno 8001 sadd  emptno 8002 smembers  emptno 返回集合全部数据 scard  获取集合长度 sismem ...

  4. RabbitMQ入门教程(一):安装和常用命令

    原文:RabbitMQ入门教程(一):安装和常用命令 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn ...

  5. JAVA重写不需要@override

    一,如下代码, package com.boot.enable.bootenable; import org.springframework.scheduling.annotation.Async; ...

  6. 在eclipse中创建第一个java应用程序,并在控制台输出“hello world”。

    package com.fs.test; public class HelloWorld { public void aMethod() { } public static void main(Str ...

  7. 将div生成图片并下载下来

    //文件需要引入html2canvas.js.jquery.js function downLoadImg(){ var element = $(".orgchart"); // ...

  8. python接口自动化 - Requests-3 高级用法

    高级用法 本篇文档涵盖了 Requests 的一些高级特性. 会话对象 会话对象让你能够跨请求保持某些参数.它也会在同一个 Session 实例发出的所有请求之间保持 cookie, 期间使用 url ...

  9. Linux下网络设置

    1.临时IP配置 # ifconfig eth0   192.168.110.118    netmask 255.255.255.0   gateway 192.168.110.2    up # ...

  10. 007-Zabbix Server 自带模板监控MySQL数据库

    监控数据库分为三种: 1.Zabbix Server 自带模板监控无密码MySQL数据库 2.Zabbix Server 自带模板监控有密码MySQL数据库 3.Zabbix Server 自带模板监 ...