【问题标题】:How to call a link with requestparameter inside loop如何在循环内调用带有请求参数的链接
【发布时间】:2019-09-23 13:28:47
【问题描述】:
我想在 URL 中引用索引,
对于如下所示的控制器,
这样当单击列表中第一项的按钮时,
对应的要调用的URL是:
/product/detailpage/index/0 ->for the first item
/product/detailpage/index/2 ->for the third item
and so on
如何修改代码和
【问题讨论】:
标签:
java
spring-boot
spring-mvc
thymeleaf
【解决方案1】:
您想看到/product/detailpage/index/0 而不是/product/detailpage/index/?idx=0?您只需要添加一个与您选择的变量名称匹配的占位符。像这样:
th:action="@{/product/detailpage/index/{idx}(idx=${iter.index})}"
或用于网址
th:url="@{/product/detailpage/index/{idx}(idx=${iter.index})}"