Thymeleaf在th:block中使用th:if

 林志岳小行克元 发布于 2023-01-04 14:56

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

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

这是我的thymeleaf / html代码




Smoke Tests






        
Test Name Tests
A Smoke Test'

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

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

}

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

 



Smoke Tests




Test Name OBI01 DEV
authAmtTesting.jmx
authTesting.jmx
CC_Crypto.jmx
ci_address.jmx
ci_cardtype_negative.jmx
ci_cardtype_positive.jmx
promoSmokeTst.jmx
tokenizedPayment.jmx

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

1 个回答
  • 此代码有效

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

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

    2023-01-04 14:59 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有