spring - http://localhost:8080/@%7B/author/(id=1)%7D
问题描述
请告诉我为什么当我点击链接时:
<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"
解决方案
为什么当我点击链接
模板中指定的 URL 是@{/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
为您翻译的原因。