显示文字 拼接字符串
<span th:text="'Welcome,'+${user.name}"> <span th:text="|Welcome, ${user.name}|"> <tr> <td>备注</td> <td>[[${wxNum.remark}]]</td> </tr> <tr> <td> 结果</td> <td>[[${wxNum.reslt}]]</td> </tr>
<div th:id="${user.id}" th:each="user : ${userList}"> <a th:href="@{/employee/}+${user.id}" th:text="#{edit}"></a> </div>
list加 onclick
<div class="my_list_item" th:each="address : ${addressList}"> <div style="overflow: hidden;"> <span th:onclick="|setDefault(${address.id})|" class="default" style="float: right; margin-right: 40rpx;">设为默认</span> </div> </div> 正确写法 最好加转义 th:onclick="'javascript:editUser(\''+${prod.id}+'\');'"
判断list是不是空
<div th:if="${not #lists.isEmpty(userList)}"> <p>size : <span th:text="${#lists.size(userList)}"/></p> </div>
if判断字符串 和 boolean
<button th:if="${register.rock.name} eq '化探'" class="layui-btn layui-btn-sm" onclick="show_tupu()">图谱</button> <div th:if="${flag}==false " style="text-align: center; line-height: 100px;" > 不可编辑 </div> <div th:if="${flag}==true" style="padding: 10px;" class="layui-form layui-form-pane" action="">
list 生成下标,索引,使用Stat变量
Stat 内置变量 使用只需 变量名+Stat即可
可以获取index,count,size,current,even,odd,first,last等属性
<li th:each="nav,d : ${application.navList}"> <a th:href="|${nav.url}|" data-track="官网|菜单栏|首页" th:text="${nav.name}">首 页</a> <ul th:class="|subnav subnav${d.index}|"> </ul> <span></span> </li>
<table class="top_10 mar_b_10" th:each="top : ${notComplianceTOP}"> <tr> <td> <!--Stat 内置变量 使用只需 变量名+Stat即可--> <b th:text="${topStat.count}"/> <span class="f_gray" th:text="${top.TOPName}"/> </td> <td> <div class="bar_progress"> <div class="bar_progress_bg" progress="60%"></div> </div> </td> <td class="f_gray" th:text="${top.TOPValue}"/> </tr> </table>
<span th:text="${#dates.format(user.createDateTimeDate, 'yyyy-MM-dd HH:mm:ss')}" ></span> <tr> <td>创建时间</td> <td>[[${#dates.format(wxNum.createDateTime, 'yyyy-MM-dd HH:mm:ss')}]]</td> </tr>
<div> <p>formatDecimal 整数部分随意,小数点后保留两位,四舍五入: <span th:text="${#numbers.formatDecimal(itdragonNum, 0, 2)}"/></p> <p>formatDecimal 整数部分保留五位数,小数点后保留两位,四舍五入: <span th:text="${#numbers.formatDecimal(itdragonNum, 5, 2)}"/></p> </div>
<tr> <td>状态</td> <td th:if="${wxNum.state==0}">查询中</td> <td th:if="${wxNum.state==1}">查询完成</td> </tr>
if判断 boolean
<div th:if="${#bools.isTrue(itdragonBool)}"> <p th:text="${itdragonBool}"></p> 输出 true </div> var f = [[${flag}]] ; $(function(){ if(f){ alert(1); }else{ alert(0); } });
<span style="margin-left: 20px;" th:text="|装箱标记:${param.xiang_bj}|"></span>
<span th:text="${session.ss}"></span> <span th:text="${#httpSession.getAttribute('ss')}">session</span> <span th:text="${#httpServletRequest.getAttribute('qq')}">req</span> <span th:text="${#httpServletRequest.getServletContext().getAttribute('pp')}">application</span> 全局对象使用这个也行 <title th:text="${application.config.webName}+' 管理系统' "></title>
输出list大小
<!-- 额外增加的一个节点(循环轮播:第一个节点是最后一张轮播) --> <div class="mui-slider-item mui-slider-item-duplicate"> <a th:href="${bannerList[bannerList.size()-1].clickUrl}"> <img th:src="${bannerList[bannerList.size()-1].imageUrl}"> </a> </div> <!-- 额外增加的一个节点(循环轮播:第一个节点是最后一张轮播) -->
三目运算
<textarea rows="3" v-model="detail" th:text="${detail==null?'':detail}" ></textarea> <input type="text" th:value="${userInfo!=null ?userInfo.phone:''}"> <td th:utext="${recordValue.monthValue != 0 ? recordValue.monthValue : ''}"> </td> 如果是0显示空字符串。 <td>[[${item.user.sex==1?'男':'女'}]]</td>
// 模糊查询 if (map.get("q") != null) { predicate.getExpressions().add(cb.or( cb.like(root.get("title"),"%"+map.get("q").toString()+"%"), cb.like(root.get("content"),"%"+map.get("q").toString()+"%") )); }
/*<![CDATA[*/
th:inline="javascript" 使用与不使用的区别
显示乱码
换一种写法 正常了。
<script th:inline="none">
<button onclick="window.open('${yuanCaiLiao.drawing.sales.qrFilePath}');" type="button" class="layui-btn layui-btn-xs layui-btn-normal">查看图纸</button> <span class="td_span">规格:[[${yuanCaiLiao.drawing.guige}]]</span>
左补0 <p th:with="num=10" th:utext="${#numbers.formatInteger(num,3)}">number format</p> <p th:with="num=10" th:utext="${#numbers.formatInteger(num,4)}">number format</p> <p th:with="num=10" th:utext="${#numbers.formatInteger(num,5)}">number format</p> <p th:with="num=10" th:utext="${#numbers.formatInteger(num,6)}">number format</p> 输出结果: <p>010</p> <p>0010</p> <p>00010</p> <p>000010</p> 千分位分隔符 <p th:with="num=1" th:utext="${#numbers.formatInteger(num,1,'COMMA')}">number format</p> <p th:with="num=10" th:utext="${#numbers.formatInteger(num,1,'COMMA')}">number format</p> <p th:with="num=100" th:utext="${#numbers.formatInteger(num,1,'COMMA')}">number format</p> <p th:with="num=1000" th:utext="${#numbers.formatInteger(num,1,'COMMA')}">number format</p> <p th:with="num=10000" th:utext="${#numbers.formatInteger(num,1,'COMMA')}">number format</p> <p th:with="num=100000" th:utext="${#numbers.formatInteger(num,1,'COMMA')}">number format</p> <p th:with="num=10" th:utext="${#numbers.formatInteger(num,2,'COMMA')}">number format</p> <p th:with="num=10" th:utext="${#numbers.formatInteger(num,3,'COMMA')}">number format</p> <p th:with="num=10" th:utext="${#numbers.formatInteger(num,4,'COMMA')}">number format</p> <p th:with="num=10" th:utext="${#numbers.formatInteger(num,5,'COMMA')}">number format</p> <p th:with="num=10" th:utext="${#numbers.formatInteger(num,6,'COMMA')}">number format</p> 输出结果: <p>1</p> <p>10</p> <p>100</p> <p>1,000</p> <p>10,000</p> <p>100,000</p> <p>10</p> <p>010</p> <p>0,010</p> <p>00,010</p> <p>000,010</p> 千分位分隔符 + 保留2位小数 <p th:with="num=1" th:utext="${#numbers.formatDecimal(num,3, 'COMMA', 2,'POINT')}">number format</p> <p th:with="num=10" th:utext="${#numbers.formatDecimal(num,3, 'COMMA', 2,'POINT')}">number format</p> <p th:with="num=100" th:utext="${#numbers.formatDecimal(num,3, 'COMMA', 2,'POINT')}">number format</p> <p th:with="num=1000" th:utext="${#numbers.formatDecimal(num,3, 'COMMA', 2,'POINT')}">number format</p> <p th:with="num=10000" th:utext="${#numbers.formatDecimal(num,3, 'COMMA', 2,'POINT')}">number format</p> <p th:with="num=100000" th:utext="${#numbers.formatDecimal(num,3, 'COMMA', 2,'POINT')}">number format</p> <p th:with="num=1000000" th:utext="${#numbers.formatDecimal(num,3, 'COMMA', 2,'POINT')}">number format</p> <p th:with="num=1234567.8" th:utext="${#numbers.formatDecimal(num,3, 'COMMA', 2,'POINT')}">number format</p> <p th:with="num=1234567.85" th:utext="${#numbers.formatDecimal(num,3, 'COMMA', 2,'POINT')}">number format</p> <p th:with="num=1234567.8797" th:utext="${#numbers.formatDecimal(num,3, 'COMMA', 2,'POINT')}">number format</p> <p th:with="num=1234567.8732" th:utext="${#numbers.formatDecimal(num,3, 'COMMA', 2,'POINT')}">number format</p> 输出结果: <p>001.00</p> <p>010.00</p> <p>100.00</p> <p>1,000.00</p> <p>10,000.00</p> <p>100,000.00</p> <p>1,000,000.00</p> <p>1,234,567.80</p> <p>1,234,567.85</p> <p>1,234,567.88</p> <p>1,234,567.87</p> 货币格式 转换成货币格式时,是根据当前的 Locale 进行转换。 <p th:with="num=1" th:utext="${#numbers.formatCurrency(num)}">number format</p> <p th:with="num=10" th:utext="${#numbers.formatCurrency(num)}">number format</p> <p th:with="num=100" th:utext="${#numbers.formatCurrency(num)}">number format</p> <p th:with="num=1000" th:utext="${#numbers.formatCurrency(num)}">number format</p> <p th:with="num=10000" th:utext="${#numbers.formatCurrency(num)}">number format</p> <p th:with="num=100000" th:utext="${#numbers.formatCurrency(num)}">number format</p> <p th:with="num=1000000" th:utext="${#numbers.formatCurrency(num)}">number format</p> <p th:with="num=1234567.8" th:utext="${#numbers.formatCurrency(num)}">number format</p> <p th:with="num=1234567.85" th:utext="${#numbers.formatCurrency(num)}">number format</p> <p th:with="num=1234567.8797" th:utext="${#numbers.formatCurrency(num)}">number format</p> <p th:with="num=1234567.8732" th:utext="${#numbers.formatCurrency(num)}">number format</p> Locale = zh_CN 时,输出结果: <p>¥1.00</p> <p>¥10.00</p> <p>¥100.00</p> <p>¥1,000.00</p> <p>¥10,000.00</p> <p>¥100,000.00</p> <p>¥1,000,000.00</p> <p>¥1,234,567.80</p> <p>¥1,234,567.85</p> <p>¥1,234,567.88</p> <p>¥1,234,567.87</p> Locale = en_US 时,输出结果: <p>$1.00</p> <p>$10.00</p> <p>$100.00</p> <p>$1,000.00</p> <p>$10,000.00</p> <p>$100,000.00</p> <p>$1,000,000.00</p> <p>$1,234,567.80</p> <p>$1,234,567.85</p> <p>$1,234,567.88</p> <p>$1,234,567.87</p> 1 2 3 4 5 6 7 8 9 10 11 Locale = de_DE 时,输出结果: <p>1,00 €</p> <p>10,00 €</p> <p>100,00 €</p> <p>1.000,00 €</p> <p>10.000,00 €</p> <p>100.000,00 €</p> <p>1.000.000,00 €</p> <p>1.234.567,80 €</p> <p>1.234.567,85 €</p> <p>1.234.567,88 €</p> <p>1.234.567,87 €</p> 百分比格式 <p th:with="num=1" th:utext="${#numbers.formatPercent(num, 1, 2)}">number format</p> <p th:with="num=1" th:utext="${#numbers.formatPercent(num, 2, 2)}">number format</p> <p th:with="num=1" th:utext="${#numbers.formatPercent(num, 3, 2)}">number format</p> <p th:with="num=1" th:utext="${#numbers.formatPercent(num, 4, 2)}">number format</p> <p th:with="num=0.80" th:utext="${#numbers.formatPercent(num, 1, 2)}">number format</p> <p th:with="num=0.808" th:utext="${#numbers.formatPercent(num, 1, 2)}">number format</p> <p th:with="num=0.80881" th:utext="${#numbers.formatPercent(num, 1, 2)}">number format</p> <p th:with="num=0.80888" th:utext="${#numbers.formatPercent(num, 1, 2)}">number format</p> <p th:with="num=3.1415926" th:utext="${#numbers.formatPercent(num, 1, 3)}">number format</p> 输出结果: <p>100.00%</p> <p>100.00%</p> <p>100.00%</p> <p>0,100.00%</p> <p>80.00%</p> <p>80.80%</p> <p>80.88%</p> <p>80.89%</p> <p>314.159%</p> ———————————————— 版权声明:本文为CSDN博主「sayyy」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/sayyy/article/details/94397479
站长微信:xiaomao0055
站长QQ:14496453