【问题标题】:http://localhost:8080/@%7B/author/(id=1)%7Dhttp://localhost:8080/@%7B/author/(id=1)%7D
【发布时间】:2021-09-03 13:43:49
【问题描述】:

当我点击链接时请告诉我原因:

<td> <a href="@{/author/(id=${book.id})}"  type="button">Перейти</a></td>

我在 url 中得到地址:http://localhost:8080/@%7B/author/(id=1)%7D?

点击链接打开的表单:form action="@{/author/(id=${book.id})}" method="get"

【问题讨论】:

  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: spring model-view-controller


【解决方案1】:

试试这个:

<a href= "@{/author/${book.id}}" type="button"></a>

【讨论】:

  • 不起作用。错误:由以下原因引起:org.thymeleaf.exceptions.TemplateInputException:解析模板时出错[错误],模板可能不存在或可能无法被任何已配置的模板解析器访问
【解决方案2】:
href="/author/${book.id}" 

【讨论】:

    【解决方案3】:

    为什么当我点击链接时

    模板中指定的网址是@{/author/(id=${book.id})}

    ${book.id} 被 Thymeleaf 解析为 1,因为这种表示法与 Thymeleaf 模式一致。现在,Spring URL 解析器会将最终 URL 视为 @{/author/(id=1)}

    Spring 遵循 RFC3986 编码和解码 URL。

    { 的 URI 百分比编码是 %7B
    } 的 URI 百分比编码为 %7D

    因此,Spring 会将 @{/author/(id=1)} 编码为 @%7B/author/(id=1)%7D

    这就是模板中的@{/author/(id=${book.id})} 为您转换为@%7B/author/(id=1)%7D 的原因。

    【讨论】:

      猜你喜欢
      • 2022-06-14
      • 1970-01-01
      • 1970-01-01
      • 2016-10-08
      • 1970-01-01
      • 2018-01-27
      • 1970-01-01
      • 1970-01-01
      • 2018-07-24
      相关资源
      最近更新 更多