【问题标题】:Using <a> tag in thymeleaf iteration在百里香迭代中使用 <a> 标签
【发布时间】:2021-03-21 23:52:37
【问题描述】:

我需要使用 thymeleaf 显示来自列表的链接列表。 我使用以下代码成功地做到了这一点:

<div class="col-12 col-md-6" th:each="ApplicationVO: ${ApplicationList}"> 
              <a class="service-link shadow" title="MMIS" href="mmis.html" target="_blank"><span th:text="${ApplicationVO.applicationName} +'&raquo'"></span></a>
          </div>

我的问题是如何将链接(href)和标题作为 ApplicationVO.applicationLink 和 ApplicationVO.displayName 放在锚标记中?

【问题讨论】:

    标签: java html thymeleaf


    【解决方案1】:

    我猜你需要使用 th:href 标签:

    <div class="col-12 col-md-6" th:each="ApplicationVO: ${ApplicationList}"> 
              <a class="service-link shadow" title="MMIS" th:href="@{${ApplicationVO.applicationLink}}" target="_blank"><span th:text="${ApplicationVO.applicationName} +'&raquo'"></span></a>
    </div>
    

    我认为您也可以像这样删除 span 标签:

    <div class="col-12 col-md-6" th:each="ApplicationVO: ${ApplicationList}"> 
              <a class="service-link shadow" title="MMIS" th:text="${ApplicationVO.applicationName} +'&raquo'" th:href="@{${ApplicationVO.applicationLink}}" target="_blank"></a>
    </div>
    

    【讨论】:

    • 先生,th:href 没有用,虽然 th:text 可以用。制作 href 会使其指向 localhost:8010/TestApp/ApplicationVO.applicationURL 而不是它的内容。
    • 确实,我忘记了 ApplicationVO.applicationLink 周围的 ${}。我已经编辑了答案。很抱歉造成混乱。
    猜你喜欢
    • 2014-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-27
    • 1970-01-01
    • 2018-03-20
    相关资源
    最近更新 更多