Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Thymeleaf th:如果表达式的计算结果不是真的_Java_Spring_Spring Mvc_Templating_Thymeleaf - Fatal编程技术网

Java Thymeleaf th:如果表达式的计算结果不是真的

Java Thymeleaf th:如果表达式的计算结果不是真的,java,spring,spring-mvc,templating,thymeleaf,Java,Spring,Spring Mvc,Templating,Thymeleaf,我试图用两个字符串计算一个表达式,它的计算结果也是true,但是当在th中使用时:如果它没有按预期工作 下面的代码是我正在尝试的 <div th:with="cntx=${#httpServletRequest.getRequestURI()}"> <li th:each="obj : ${list}" th:with="path=${obj.path}" th:if="${path == cntx}"> <sp

我试图用两个字符串计算一个表达式,它的计算结果也是true,但是当在th中使用时:如果它没有按预期工作

下面的代码是我正在尝试的

<div th:with="cntx=${#httpServletRequest.getRequestURI()}">
   <li th:each="obj : ${list}" th:with="path=${obj.path}"
                    th:if="${path == cntx}">
    <span th:text="${obj.title}"></span>
   </li>
</div>

  • 上述代码的上下文

    我有一个对象列表,其中包含必须在其中一个对象中显示的链接。我试图用th:if来表示字符串相等,但是这里的表达式${path==cntx}由于某种原因失败,并且没有显示在最终呈现的页面上


    我甚至检查了path和URI值,它们是相等的,即/test for path和/test for cntx,如果我使用th:text打印出来,则计算结果为true。非常奇怪的行为。

    我猜if是在
    th:with
    之前计算的。你可以试试:

    <th:block th:each="obj : ${list}" th:with="path=${obj.path}">
      <li  th:if="${path == cntx}">...</li>
    </th:block>
    
    
    

  • 但是,对我来说,它会打印一些有用的异常(例如:找不到变量路径)。

    谢谢您的建议。。工作很有魅力。:)