SpringBoot中使用thymeleaf的trim方法进行判断字符串是否相等

场景

在thymeleaf中进行string字符串的数字进行判断是否相等进而显示相应的中文内容。

但是后台传递的数据是‘1 ’

即1的后面有一个空格。

所以在thymeleaf中进行判读时需要使用trim方法进行去掉空格再进行判断。

内嵌变量

为了模板更加易用,Thymeleaf还提供了一系列Utility对象(内置于Context中),可以通过#直接访问,

其中有

strings : 字符串对象的功能类,contains,startWiths,prepending/appending等等。

${#strings.trim(str)}

实现

具体示例代码

<div class="form-group col-md-4 ml_10"><label th:value="${detailsVO.status}">单据状态:</label>
                            <input type="text" th:value="未执行" th:if="${detailsVO==null || detailsVO.status ==null ?'':#strings.trim(detailsVO.status)=='0'}" readonly="readonly" class="form-control"/>
                            <input type="text" th:value="执行中" th:if="${detailsVO==null || detailsVO.status ==null ?'':#strings.trim(detailsVO.status)=='1'}" readonly="readonly" class="form-control"/>
                            <input type="text" th:value="已执行" th:if="${detailsVO==null || detailsVO.status ==null ?'':#strings.trim(detailsVO.status)=='2'}" readonly="readonly" class="form-control"/>
                        </div>

猜你喜欢

转载自blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/90202414