【问题标题】:How to build URL path with Request Param inside it with thymeleaf?如何使用 thymeleaf 在其中构建带有 Request Param 的 URL 路径?
【发布时间】:2018-06-16 04:18:46
【问题描述】:

我正在使用 thymeleaf,我希望我的链接是: http://localhost:8080/item?id=1/cmets

我试过这个选项:

<a th:href="@{item#/comments(id=${item.id})}" th:text="${item.title}"></a>

它给了我: http://localhost:8080/item?id=1#/cmets
但是符号 # 是多余的。

我不确定我是否在控制器中正确接收到它:

@GetMapping(value = "/item/comments")
public String showItemComments(@RequestParam Long id, Model model) {
    // do something...
}

我将不胜感激。

【问题讨论】:

  • 您正在尝试在查询参数中使用路径参数。这没有多大意义。只需使用/items/1/comments。一旦以? 开始查询字符串,就不能再添加路径参数了。
  • 感谢您的帮助。

标签: java spring spring-mvc spring-boot thymeleaf


【解决方案1】:

我遇到了类似的问题,我通过更换控制器实现了解决方案

@GetMapping(value = "/item/comments/{id}")
public String showItemComments(@PathVariable Long id, Model model) {
}

【讨论】:

    猜你喜欢
    • 2019-09-25
    • 2018-09-19
    • 1970-01-01
    • 2013-07-04
    • 1970-01-01
    • 2019-07-20
    • 2013-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多