[英]Thymeleaf 2 expressions in URL
我正在使用 Spring Boot 2.1.6.RELEASE 、 Thymeleaf 3.0.11.RELEASE 。 我有
<a class="k-button" th:href="@{/customer/view/{id}(id=${accountObject.id})}" style="min-width: 0; color: green;" title="Xem"><span class="k-icon k-i-preview"></span></a>
它工作正常,生成到http://localhost:8080/customer/42
。 我试试
<a class="k-button" th:href="@{/customer/view/{type}(type=${accountObject.accountObjectType})/{id}(id=${accountObject.id})}" style="min-width: 0; color: green;" title="Xem"><span class="k-icon k-i-preview"></span></a>
它没有按预期工作,我希望它生成到http://localhost:8080/customer/1/42
( accountObject.accountObjectType
= 2
)
我需要像/customer/1/
这样的东西,因为它将是 Spring MVC 控制器中的@PathVariable("type") Integer type
。
如何在 Thymeleaf URL 中放置 2 个表达式?
一个 URI 模板中可以有多个占位符; 最后一次提供所有替换。 它应该是这样的:
th:href="@{/customer/view/{type}/{id}(type=${accountObject.accountObjectType},id=${accountObject.id})}"
(我还认为您可能不需要每个替换值的{}
,但这不会有什么坏处。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.