Thymeleaf在th:block中使用th:if

use*_*234 1 html each boolean thymeleaf

我是thymeleaf的新手,正在尝试创建一个html表,其中的boolean值决定文本在某些列中的通过还是失败。

SmokeTest.passOrFailArray是布尔数组。现在,smokeTest.name显示在该列中,但是通过或失败的文本完全不显示。

这是我的thymeleaf / html代码

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Smoke Tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>

<table border="1" style="width:300px">
<tr>
    <td>Test Name</td>
    <td th:each="testsThatRan : ${testsThatRan}"
    th:text="${testsThatRan}">Tests</td>
</tr>
<th:block th:each="smokeTest : ${smokeTests}">
<tr>
   <td th:text="${smokeTest.name}">A Smoke Test'</td>
   <th:block th:each="smokeTest.passOrFailArray : ${smokeTest.passOrFailArray}">
        <td th:if="${smokeTest.passOrFailArray} == true" th:text="Passed"></td>
        <td th:if="${smokeTest.passOrFailArray} == false" th:text="failed"></td>

   </th:block>
</tr>
</th:block>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是我在百里香中用作变量的类

public testers() throws IOException {

    localPath = "/Users/dansbacher14/Documents/workspace/OBI_nightly_test/src/OBI_ci_scripts_tests";
    remotePath = "ssh://git@stash.ops.aol.com:2022/obi/obi_ci_scripts.git";
    localRepo = new FileRepository(localPath + "/.git");
    pathToSmoke = "BPS/GPS/GATHR/SMOKE";
    pathToODirectory = "test-results";
    git = new Git(localRepo);
}

public static <C> void testClone() throws IOException, InvalidRemoteException, TransportException, GitAPIException 
{

    Git.cloneRepository().setURI(remotePath).setDirectory(new File(localPath)).call();
}


//____________SETTERS AND GETTERS __________________________________________________________________________________

public void setName(String name)
{
    jmxName = name;
}

public String getName()
{
    return jmxName;
}


public boolean[] getPassOrFailArray()
{
    return passOrFailArray;
}

public String getLocalPath()
{
    return localPath;
}
Run Code Online (Sandbox Code Playgroud)

}

这是浏览器显示源代码的方式。

 <!DOCTYPE HTML>

<html>
<head>
<title>Smoke Tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>

<table border="1" style="width:300px">
<tr>
    <td>Test Name</td>
    <td>OBI01</td>
    <td>DEV</td>
</tr>

<tr>
   <td>authAmtTesting.jmx</td>



</tr>


<tr>
   <td>authTesting.jmx</td>




</tr>


<tr>
   <td>CC_Crypto.jmx</td>





</tr>


<tr>
   <td>ci_address.jmx</td>


</tr>


<tr>
   <td>ci_cardtype_negative.jmx</td>



</tr>


<tr>
   <td>ci_cardtype_positive.jmx</td>


</tr>


<tr>
   <td>promoSmokeTst.jmx</td>



</tr>


<tr>
   <td>tokenizedPayment.jmx</td>


</tr>

</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

是否可以在百里香中做这样的事情?如果可以,我该如何进行这项工作?谢谢

use*_*234 5

此代码有效

<th:block th:each="pf : ${smokeTest.passOrFailArray}">
        <td th:if="${pf} == true" th:text="Passed"></td>
        <td th:if="${pf} == false" th:text="failed"></td>

   </th:block>
Run Code Online (Sandbox Code Playgroud)

问题是我在每个循环中错误地命名了我的变量。名称中不能包含句点。