主要用到的知识就是thyme leaf中的条件运算符

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

  • 当条件condition成立时返回then。否则返回else

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

实际运用中的例子(我觉得我这个例子好详细了、这要是在搞不懂。阿西吧)

1、首先看数据库中的字段
我这里使用整形 0 1 模拟订单的付款、发货、收货、品论的状态。
在这里插入图片描述
2、这里将从数据库中查询到的数据通过 mode.addtribute传送的前台
在这里插入图片描述
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、前台效果展示
在这里插入图片描述

posted on 2022-08-28 22:19  热爱技术的小郑  阅读(38)  评论(0编辑  收藏  举报