我正在使用 thymeleaf ,我希望我的链接是: http://localhost:8080 /item?id=1/comments
我尝试过这个选项:
<a th:href="@{item#/comments(id=${item.id})}" th:text="${item.title}"></a>
它给了我:
http://localhost:8080 /item?id=1#/comments
但符号 #
是多余的。
我不确定我的 Controller 是否正确接收到它:
@GetMapping(value = "/item/comments")
public String showItemComments(@RequestParam Long id, Model model) {
// do something...
}
如果有任何帮助,我将不胜感激。
最佳答案
我遇到了类似的问题,我通过更改 Controller 解决了
@GetMapping(value = "/item/comments/{id}")
public String showItemComments(@PathVariable Long id, Model model) {
}
关于java - 如何使用 thymeleaf 构建包含请求参数的 URL 路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48129082/