日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Thymeleaf中使用if和unless实现状态的判断显示达到if-else逻辑判断的效果

發布時間:2025/3/19 编程问答 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Thymeleaf中使用if和unless实现状态的判断显示达到if-else逻辑判断的效果 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

場景

Thymeleaf官方文檔:

https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#introducing-thymeleaf

官方文檔說明:

有時,只有在滿足特定條件時,才需要顯示模板的片段。

官方使用示例:

<table><tr><th>NAME</th><th>PRICE</th><th>IN STOCK</th><th>COMMENTS</th></tr><tr th:each="prod : ${prods}" th:class="${prodStat.odd}? 'odd'"><td th:text="${prod.name}">Onions</td><td th:text="${prod.price}">2.41</td><td th:text="${prod.inStock}? #{true} : #{false}">yes</td><td><span th:text="${#lists.size(prod.comments)}">2</span> comment/s<ahref = "comments.html"<BR>????????th:href="@{/product/comments(prodId=${prod.id})}"th:if="${not #lists.isEmpty(prod.comments)}">view</a></td></tr> </table>

注意:

th:if屬性不僅計算布爾型數據,還能計算表達式的值為true時也遵守如下規則:

1.如果值為NULL:

則th:if將計算為false

2.如果值不為NULL:

①值為布爾型,為true。

②值為數字,為非0。

③值為字符,為非0。

④值為字符串,不為“false”、"off"、“no”

還有,th:if有一個逆屬性,th:unless,除非。。。

官方舉例:

<a href="comments.html"th:href="@{/comments(prodId=${prod.id})}"th:unless="${#lists.isEmpty(prod.comments)}">view</a>

實現

?

<div class="form-group col-md-4 ml_10"><label>業務物流類型:</label><input type="text" th:value="物料清潔上料" th:if="${detailsVO==null || detailsVO.orderType ==null ?'':detailsVO.orderType=='01'}" readonly="readonly" class="form-control"/><input type="text" th:value="托盤清潔上料" th:if="${detailsVO==null || detailsVO.orderType ==null ?'':detailsVO.orderType=='02'}" readonly="readonly" class="form-control"/><input type="text" th:value="托盤清潔上臺" th:if="${detailsVO==null || detailsVO.orderType ==null ?'':detailsVO.orderType=='03'}" readonly="readonly" class="form-control"/><input type="text" th:value="廢料包材出庫" th:if="${detailsVO==null || detailsVO.orderType ==null ?'':detailsVO.orderType=='04'}" readonly="readonly" class="form-control"/><input type="text" th:value="廢料托盤出庫" th:if="${detailsVO==null || detailsVO.orderType ==null ?'':detailsVO.orderType=='05'}" readonly="readonly" class="form-control"/><input type="text" th:value="不良品出庫" th:if="${detailsVO==null || detailsVO.orderType ==null ?'':detailsVO.orderType=='06'}" readonly="readonly" class="form-control"/><input type="text" th:value="清潔設備補盤" th:if="${detailsVO==null || detailsVO.orderType ==null ?'':detailsVO.orderType=='07'}" readonly="readonly" class="form-control"/><input type="text" th:value="待清潔入庫" th:if="${detailsVO==null || detailsVO.orderType ==null ?'':detailsVO.orderType=='08'}" readonly="readonly" class="form-control"/><input type="text" th:value="不良品暫估" th:if="${detailsVO==null || detailsVO.orderType ==null ?'':detailsVO.orderType=='09'}" readonly="readonly" class="form-control"/><input type="text" th:value="未知狀態" th:unless="${detailsVO==null || detailsVO.orderType ==null ?'':detailsVO.orderType=='01'||detailsVO.orderType=='02'||detailsVO.orderType=='03'||detailsVO.orderType=='04'||detailsVO.orderType=='05'||detailsVO.orderType=='06'||detailsVO.orderType=='07'||detailsVO.orderType=='08'||detailsVO.orderType=='09'}" readonly="readonly" class="form-control"/></div>


?

總結

以上是生活随笔為你收集整理的Thymeleaf中使用if和unless实现状态的判断显示达到if-else逻辑判断的效果的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。