天天看點

springboot+thymeleaf中前台頁面展示中、将不同的數字替換成不同的字元串。使用條件運算符

主要用到的知識就是thyme leaf中的條件運算符

表達式:(condition)?:then:else

  • 當條件condition成立時傳回then。否則傳回else

具體代碼:​

​<td th:text="${buylog.getIs_pay()==0} ? '未付款':'已付款'"></td>​

實際運用中的例子(我覺得我這個例子好詳細了、這要是在搞不懂。阿西吧)

1、首先看資料庫中的字段

我這裡使用整形 0 1 模拟訂單的付款、發貨、收貨、品論的狀态。

springboot+thymeleaf中前台頁面展示中、将不同的數字替換成不同的字元串。使用條件運算符

2、這裡将從資料庫中查詢到的資料通過 mode.addtribute傳送的前台

springboot+thymeleaf中前台頁面展示中、将不同的數字替換成不同的字元串。使用條件運算符

3、前台接受資料需要根據不同的整形參數判斷、展示不同的文字

<td th:text="${buylog.getIs_pay()==0} ? '未付款':'已付款'"></td>
                    <td th:text="${buylog.getIs_fahuo()==0}? '未發貨':'已發貨'"></td>
                    <td th:text="${buylog.getIs_gain()==0} ? '未收貨':'已收貨'"></td>
                    <td th:text="${buylog.getIs_comment()==0} ? '未評論':'已評論'"></td>      

4、前台效果展示