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>

03-03:springBoot 整合thymeleaf的更多相关文章

  1. 【Springboot】Springboot整合Thymeleaf模板引擎

    Thymeleaf Thymeleaf是跟Velocity.FreeMarker类似的模板引擎,它可以完全替代JSP,相较与其他的模板引擎,它主要有以下几个特点: 1. Thymeleaf在有网络和无 ...

  2. Springboot整合thymeleaf模板

    Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...

  3. 三、SpringBoot整合Thymeleaf视图

    目录 3.1 Thymeleaf视图介绍 3.2 创建SpringBoot项目 3.2 配置Thymeleaf 3.3 编写Demo 3.4 小结 3.1 Thymeleaf视图介绍 先看下官网的介绍 ...

  4. SpringBoot 整合 Thymeleaf & 如何使用后台模板快速搭建项目

    如果你和我一样,是一名 Java 道路上的编程男孩,其实我不太建议你花时间学 Thymeleaf,当然他的思想还是值得借鉴的.但是他的本质在我看来就是 Jsp 技术的翻版(Jsp 现在用的真的很少很少 ...

  5. SpringBoot 整合thymeleaf

    1.Thymeleaf介绍(官网推荐:https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html) Thymeleaf是跟Veloc ...

  6. springboot整合thymeleaf+tiles示例

    网上关于此框架的配置实在不多,因此想记录下来以防忘记 因为公司框架基于上述(公司采用gradle构建项目,楼主采用的是maven),所以楼主能少走些弯路: 1.创建springboot-maven项目 ...

  7. SpringBoot:2.SpringBoot整合Thymeleaf模板引擎渲染web视图

    在Web开发过程中,Spring Boot可以通过@RestController来返回json数据,那如何渲染Web页面?Spring Boot提供了多种默认渲染html的模板引擎,主要有以下几种: ...

  8. springboot整合Thymeleaf模板引擎

    引入依赖 需要引入Spring Boot的Thymeleaf启动器依赖. <dependency> <groupId>org.springframework.boot</ ...

  9. SpringBoot学习9:springboot整合thymeleaf

    1.创建maven项目,添加项目所需依赖 <!--springboot项目依赖的父项目--> <parent> <groupId>org.springframewo ...

  10. SpringBoot整合Thymeleaf

    一个整合Thymeleaf与Mybatis的CRUD例子 整合Mybatis例子 一.添加maven依赖 <dependency> <groupId>org.springfra ...

随机推荐

  1. c#+web下载文件夹

    最近公司在做工程项目,实现文件夹下载. 网上找了很久,发现网上的代码都有相似的问题,不过最终还是让我找到了一个符合的项目. 工程: 进行项目文件夹下载功能分析,弄清楚文件夹下载的原理,提供的数据支持. ...

  2. Codeforces821B Okabe and Banana Trees 2017-06-28 15:18 25人阅读 评论(0) 收藏

    B. Okabe and Banana Trees time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  3. Vue的路由设置

    一.路由基础介绍 1.什么是前端路由? 路由是根据不同的url地址展示不同的内容或页面 前端路由就是把不同路由对应不同的内容或页面的任务交给前端来做,之前是通过服务器根据url的不同返回不同的页面实现 ...

  4. MEAN 27

    添加评论主题页,在26的基础上. 新建了很多文件 Error: Cannot find module './controllers/customers_c' 解决办法:../ 接下来做function ...

  5. 关于分页插件PageHelper

    上课的时候学习了分页插件,感受到了它的强大,这里总结如下: 1.首先在spring配置文件中引入依赖jar包: <dependency> <groupId>com.github ...

  6. spring 框架整合mybatis的源码分析

    问题:spring 在整合mybatis的时候,我们是看不见sqlSessionFactory,和sqlsession(sqlsessionTemplate 就是sqlsession的具体实现)的,这 ...

  7. Android-HttpClient-Get与Post请求登录功能

    HttpClient 是org.apache.http.* 包中的: 第一种方式使用httpclient-*.jar (需要在网上去下载httpclient-*.jar包) 把httpclient-4 ...

  8. MySQL5.7Gtid主从复制总是遇到日志被清等出现无法正常主从复制

    最近最是在MySQL5.7上的的gtid主从复制问题总是遇上下面问题: Last_Error: Coordinator stopped because there were error(s) in t ...

  9. net 把指定 URI 的资源下载到本地

    DirectoryInfo dir = new DirectoryInfo(AppContext.BaseDirectory); var path = dir.FullName + @"te ...

  10. ASP.Net MVC OA项目笔记<四>

    1.1.1 EF线程唯一 在数据层中用到了EF的实例,在数据会话层也用到了,所以在一个请求中只能创建一个EF实例(线程内唯一对象),把它封装成工厂类 1.1.2 为了防止相互引用,循环引用,所以这个工 ...