zoukankan      html  css  js  c++  java
  • 03-03:springBoot 整合thymeleaf

    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>
           
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
       

  • 相关阅读:
    js中图片base64格式转文件对象
    vue中添加百度统计代码
    一个基于vueCli3的移动端多页面脚手架
    一个基于WabPack4的 Vue 多页面原生写法脚手架
    GPU加速有坑?
    mac效率工具
    git操作详解
    高性能移动端开发
    浅析vue数据绑定
    移动端适配
  • 原文地址:https://www.cnblogs.com/wangjianly/p/9854545.html
Copyright © 2011-2022 走看看