thymleaf模板实例总结

在这里总结一下thymleaf项目中用到的语法
前提:request.setattribute传值到页面
例:在这里插入图片描述
thymleaf具体语法:
1.基础取值

<div class="layui-input-inline">
    <input type="text" id="L_warehouseAddress"  
           name="warehouseAddress" 
           th:value="${data.warehouse.warehouseAddress}">
 </div>

2.float后缀去除多余的0(数字格式化)
如:2.0

 <input type="text"  
        lay-verify="warehouseCapacity"  
        name="warehouseCapacity"   class="layui-input" 
        th:value="${#numbers.formatDecimal(data.warehouse.warehouseCapacity,1,0)}" >

3.select下拉框遍历

<option  th:each="units : ${units}" 
              th:value="${units.unitId}" 
              th:text="${units.unitBasic}">
              </option>

4.select固定选项判断选中当前框

 <select id="L_clienteleLv" name="clienteleLv" required="">
   <option value=""></option>
   <option value="潜在"  th:selected="${clientele.clienteleLv == '潜在'}">潜在</option>
   <option value="普通"  th:selected="${clientele.clienteleLv == '普通'}">普通</option>
   <option value="重要"  th:selected="${clientele.clienteleLv == '重要'}">重要</option>
 </select>

5.select动态选项选中对应框

<select id="L_managePower" name="managePower" required="">
      <option  th:each="units : ${data.units}" 
               th:value="${units.unitId}" 
               th:text="${units.unitBasic}"  
               th:selected="(${units.unitId} == ${data.warehouse.unitId})">
      </option>
</select>

6.if判断

 <option th:if="${session.mm.managePower == 0}" 
         th:text="系统管理员">
 </option>

为true显示该选项,为false不显示

7.form表单提交

 <form  th:action="@{'/manage/selectManage'}" class="layui-form layui-col-md12 x-so">
     <input type="text" 
                name="manageName" 
                placeholder="请输入名称" 
                autocomplete="off" 
                id="manageName" 
                class="layui-input">
      <button class="layui-btn layui-btn-warm" >
          <i class="layui-icon">&#xe615;</i>
      </button>
 </form>

8.点击打开嵌套页面并传值

<a  th:onclick="x_admin_show('编辑','/psi/manage/manage-edit?manageId='+'[[${manage.manageId}]]')" href="javascript:;"></a>

9.点击事件传值

<a title="删除"   th:onclick="'javascript: del('+${manage.manageId}+','+${manage.managePower}+')' " href="javascript:;">

10.switch语法

<li th:switch="${manage.managePower }">
       <p th:case="0"> 角色: 超级管理员</p>
       <p th:case="1"> 角色: 系统管理员</p>
       <p th:case="2"  >角色: 采购员</p>
       <p th:case="3">  角色: 销售员</p>
       <p th:case="4" > 角色: 库存管理员</p>
</li>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值