【问题标题】:Thymeleaf href urlThymeleaf href 网址
【发布时间】:2018-05-17 13:18:43
【问题描述】:

我正在尝试通过循环遍历列表来为我的页面中的内容动态生成链接,但出现“解析错误”

我尝试了https://www.thymeleaf.org/doc/articles/standardurlsyntax.html中提到的:

<a th:href="@{/order/{id}/details(id=3,action='show_all')}">

代码:

        <li th:each="param : ${paramList}">
            <span th:text="${placeholder}">This is displaying the value of placeholder correctly</span>

            <!-- The value I am trying to achieve is href="/member/team/ValueFromPlaceholderVariable?team=TeamName&page=PageName" -->

            <a th:href="@{/member/team/{PlaceName}(PlaceName=${placeholder},team=${param.TeamName},page=${param.PageName})}">Page</a>
        </li>

如何生成 href 链接?

【问题讨论】:

  • 你可以试试&lt;a th:href="@{/member/team/__${placeholder}__(team=${param.TeamName},page=${param.PageName})}"&gt;Page&lt;/a&gt;
  • 你所拥有的看起来是正确的。究竟是什么错误?
  • @Metroids:链接库“/member/team/{PlaceName}”不能是上下文相关的(/...),除非用于执行引擎的上下文实现了 org.thymeleaf.context.IWebContext界面(模板:“介绍” - 第 12 行,第 16 列)
  • 如果我在开头删除斜线,那么它似乎可以工作。我需要更多地测试它。 &lt;a th:href="@{member/team/{PlaceName}(PlaceName=${placeholder},team=${param.TeamName},page=${param.PageName})}"&gt;Page&lt;/a&gt;

标签: spring-boot thymeleaf


【解决方案1】:

去掉开头的斜线

<a th:href="@{member/team/{PlaceName}(PlaceName=${placeholder},team=${param.TeamName},page=${param.PageName})}">Page</a>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-12
    • 2021-03-12
    • 2016-10-02
    • 2021-05-28
    • 2018-10-26
    • 2011-07-12
    • 1970-01-01
    相关资源
    最近更新 更多