【问题标题】:Thymeleaf and SpringMVC, how to use pathvariableThymeleaf 和 SpringMVC,如何使用路径变量
【发布时间】:2019-03-07 11:46:19
【问题描述】:

我的控制器如下所示:

@RestController
class MockRestController {

    @RequestMapping(method = [RequestMethod.POST], value = ["/mocks/{id}/start"])
    fun startMock(@PathVariable id: String): ResponseEntity<String> {
        ...
    }

这很好用:

<h1 class="title is-2">
    Mock #[[${id}]] control page
</h1>

但是,我的表单操作不起作用:

<form action="/mocks/${id}/start" method="post">

我该如何使用它?

【问题讨论】:

    标签: spring-mvc thymeleaf


    【解决方案1】:

    试试这样。这里${id} 包含您的变量值。

    <form th:action="@{/mocks/{id}/start(id=${id})}" method="post">
    

    【讨论】:

      【解决方案2】:

      它正在工作。

      <form th:action="@{'/mocks/' + ${id} + '/start'}" method="post">
      

      【讨论】:

        猜你喜欢
        • 2016-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-19
        相关资源
        最近更新 更多