我是thymeleaf的新手,我正在尝试创建一个html表,其中布尔值决定文本在某些列中是通过还是失败。
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>
这是我用作百里香叶变量的课程
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>
是否可以在百里香中做这样的事情?如果是这样我怎么能做这个工作?感谢
答案 0 :(得分:4)
此代码有效
<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>
问题是我在每个循环中错误地命名我的变量。该名称不能包含句号。