gpt4 book ai didi

html - Thymeleaf 使用 th :if within a th:block

转载 作者:行者123 更新时间:2023-12-02 17:37:45 25 4
gpt4 key购买 nike

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

SmokeTest.passOrFailArray 是一个 boolean 数组。现在 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>

这是我在 thymeleaf 中用作变量的类

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;
}

这是浏览器呈现源代码的方式。

 <!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>

是否可以在 thymeleaf 中做这样的事情?如果是这样,我怎样才能使这项工作?谢谢

最佳答案

这段代码有效

<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>

问题是我在 each 循环中错误地命名了我的变量。名称中不能有句点。

关于html - Thymeleaf 使用 th :if within a th:block,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24636630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com