thymeleaf 语法详解
1.变量输出:
 th:text :在页面中输出某个值
 th:value :将一个值放到input标签中的value中。
2.判断字符串是否为空
 ①:调用内置对象一定要用#
 ②:大部分的内置对象都已s结尾(strings,numbers,dates)
 ${#strings.isEmpty(msg)}:判断字符串是否为空,如果为空返回true 否则返回false
 ${#strings.contains(msg,'T')} :判断字符串是否包含指定的子串,如果包含返回 true,否则返回 false
 ${#strings.startsWith(msg,'a')}:判断当前字符串是否以子串开头,如果是返回 true,否则返回 false
 ${#strings.endsWith(msg,'a')}:判断当前字符串是否以子串结尾,如果是返回 true,否则返回 false
 ${#strings.length(msg)}:返回字符串的长度
 ${#strings.indexOf(msg,'h')}:查找子串的位置,并返回该子串的下标,如果没找到则返回-1
 ${#strings.substring(msg,13)}:截取子串,用户与 jdk String 类下 SubString 方法相同
 ${#strings.substring(msg,13,15)}:截取子串,用户与 jdk String 类下 SubString 方法相同
 ${#strings.toUpperCase(msg)}:字符串转大小写。
 ${#strings.toLowerCase(msg)}:字符串转大小写。

3.日期格式化处理
 ${#dates.format(key)}:格式化日期,默认的以浏览器默认语言为格式化标准
 ${#dates.format(key,'yyy/MM/dd')}:按照自定义的格式做日期转换
 ${#dates.year(key)}:year:取年
 ${#dates.month(key)}:Month:取月
 ${#dates.day(key)}:Day:取日

4.条件判断
  ①:th:if
    <span th:if="${sex} == '男'"> 性别:男 </span>
    <span th:if="${sex} == '女'"> 性别:女 </span>
  ②:th:switch
    <div th:switch = "${id}" >
        <span th:case = "1">1</span>
        <span th:case = "2">2</span>
        <span th:case = "3">3</span>
    </div>

5.迭代遍历(对集合的遍历)
    ①:th:each
    <table border="1">
       <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Age</th>
       </tr>
       <tr th:each="u : ${list}">
        <td th:text="${u.userid}"></td>
        <td th:text="${u.username}"></td>
        <td th:text="${u.userage}"></td>
       </tr>
    </table>
    ②:th:each 状态变量
    1.index 当前迭代器的索引,从0开始
    2.count 当前迭代对象的计数,从1开始
    3.size 被迭代对象的长度
    4.even/odd:布尔值,当前循环是否是偶数/奇数 从 0 开始
    5.first:布尔值,当前循环的是否是第一条,如果是返回 true 否则返回 false
    6.last:布尔值,当前循环的是否是最后一条,如果是则返回 true 否则返回 false
    
    ③.th:each 迭代Map
    <table border="1">
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Age</th>
        </tr>
        <tr th:each="maps : ${map}">
            <td th:each="entry:${maps}"  th:text="${entry.value.userid}" ></td>
            <td th:each="entry:${maps}"  th:text="${entry.value.username}"></td>
            <td th:each="entry:${maps}"  th:text="${entry.value.userage}"></td>
        </tr>
    </table>
6.域对象操作
1.httpServletRequest

7.URL表达式
th:herf
th: src
 ①:url表达式语法
 @{} 基本语法构成
 ②:URL类型
     1.绝对路径
        <a th:href="@{http://www.baidu.com}" >绝对路径1</a>
     2.相对路径
        一、相对于当前项目的根(相对于项目的上下文的相对路径)
            <a th:href="@{show}">相对路径</a>
        二、相对于服务器路径的根
            <a th:href="@{~/project/recousename}">相对服务器的根路径</a>
  ③:在URL中实现参数的传递
     1.<a th:href="@{show(id=1,name=wj)}">传参</a>
  ④:在url中通过restful方式进行参数的传递
     1.<a th:href="@{show/{id}/(id=1,name=wj)}">传参-restful</a>

thymeleaf 的使用的更多相关文章

  1. spring boot(四):thymeleaf使用详解

    在上篇文章springboot(二):web综合开发中简单介绍了一下thymeleaf,这篇文章将更加全面详细的介绍thymeleaf的使用.thymeleaf 是新一代的模板引擎,在spring4. ...

  2. Thymeleaf

    1.在html顶部添加 <html xmlns:th="http://www.thymeleaf.org"> 2.url表达式 @{...} <link rel= ...

  3. Thymeleaf 模板的使用

    Thymeleaf是现代化服务器端的Java模板引擎,不同与JSP和FreeMarker,Thymeleaf的语法更加接近HTML,并且也有不错的扩展性.详细资料可以浏览官网.本文主要介绍Thymel ...

  4. vert.x学习(三),Web开发之Thymeleaf模板的使用

    在vert.x中使用Thymeleaf模板,需要引入vertx-web-templ-thymeleaf依赖.pom.xml文件如下 <?xml version="1.0" e ...

  5. 页面上使用 Thymeleaf 的内联js不当造成了 java.lang.StackOverflowError: null 问题

    由于在页面上内联js使用不当,从而在从 Controller 跳转到页面时发生了以下错误: java.lang.StackOverflowError: null at org.thymeleaf.ut ...

  6. Thymeleaf 与 Javascript

    在 javascript 代码中使用 Thymeleaf 模板引擎: <script th:inline="javascript"> $("#content& ...

  7. Thymeleaf+SpringMVC,如何从模板中获取数据

    Thymeleaf+SpringMVC,如何从模板中获取数据 在一个典型的SpringMVC应用中,带@Controller注解的类负责准备数据模型Map的数据和选择一个视图进行渲染.这个模型Map对 ...

  8. Thymeleaf+Spring整合

    前言 这个教程介绍了Thymeleaf与Spring框架的集成,特别是SpringMvc框架. 注意Thymeleaf支持同Spring框架的3.和4.版本的集成,但是这两个版本的支持是封装在thym ...

  9. thymeleaf常用标签

    1. th:checked ,th:selected标签<input type="radio" value="M" name="gender&q ...

  10. thymeleaf的常见用法

    1,th:属性名="",就可以直接修改控件的属性,比如 <input th:type="button" th:name="xinxin" ...

随机推荐

  1. 源码安装 odoo12 -- 问题记录

    odoo12启动过程中遇到的问题,及解决办法:1.ImportError: No module named ‘win32service’pipenv install pypiwin32 2.Impor ...

  2. php一些简单的作业题

  3. Python中添加中文注释报错SyntaxError: Non-UTF-8 code starting with '\xc1'

    问题:在文本编辑器中编辑Python文件时添加中文注释,运行python文件时报错.SyntaxError: Non-UTF-8 code starting with '\xc1' 解决方法:在文本开 ...

  4. ubuntu中给python3安装opencv

    一.安装相关工具包******注意:以下3,4,5,6为可选项,根据需求安装******1.更新库 sudo apt-get update sudo apt-get upgrade 2.安装从源码构建 ...

  5. mui.fire()触发自定义事件

    导读:添加自定义事件监听操作和标准js事件监听类似,可直接通过window对象添加,通过mui.fire()方法可触发目标窗口的自定义事件. 监听自定义事件 添加自定义事件监听操作和标准js事件监听类 ...

  6. jQuery基础语法

    一.选择器(同css) 1.基本选择器 $("div") 通过标签名获取标签 $("#id") 通过id获取标签 $(".class") 通 ...

  7. GitHub--创建新的分支(转)

    如何在 GitHub 的项目中创建一个分支呢? 其实很简单啦,直接点击 Branch,然后在弹出的文本框中添加自己的 Branch Name 然后点击蓝色的Create branch就可以了,这样一来 ...

  8. ubuntu 配置jdk报错解决办法

    vi /etc/profile ,添加如下代码 export JAVA_HOME=/home/mark/android/jdk1.8 export JRE_HOME=/home/mark/androi ...

  9. 团队作业第五周(HCL盐酸队)

    一.Alpha版本测试报告 1.测试计划 测试项目 上下移动   左右移动   发射子弹   与敌方坦克进行攻击 2.测试过程 测试截图 错误记录(提交issues到码云团队项目) 3.测试找出的bu ...

  10. WCF双工通信单工通信

    1.单工模式 单向通信,指通信只有一个方向进行,即从客户端流向服务,服务不会发送响应,而客户端也不会期望会有响应.这种情况下,客户端发送消息,然后继续执行 运行后报错: 2.双工模式 双工模式的特点是 ...