Spring mvc 通过thymeleaf中的url将id从视图发布到控制器

Spring mvc 通过thymeleaf中的url将id从视图发布到控制器,spring-mvc,model-view-controller,spring-boot,thymeleaf,Spring Mvc,Model View Controller,Spring Boot,Thymeleaf,我想在我的Spring Boot应用程序中通过ID找到一个用户。 控制器方法为: @RequestMapping(value = "finduser/{id}", method = RequestMethod.GET) public User get(@PathVariable Long id) throws NotFoundException { log.info("Invoked method: get with ID: " + id); log.warn("Searchin

我想在我的Spring Boot应用程序中通过ID找到一个用户。 控制器方法为:

@RequestMapping(value = "finduser/{id}", method = RequestMethod.GET)
public User get(@PathVariable Long id) throws NotFoundException {
    log.info("Invoked method: get with ID: " + id);
    log.warn("Searching for user with ID " + id);
    User findOne = userRepository.findOne(id);
    if (findOne == null){
        log.error("Unexpected error, User with ID " + id + " not found");
        throw new NotFoundException("User with ID " + id + " not found");
    }
    log.info("User found. Sending request back. ID of user is " + id);
    return findOne;
}
myfinduser.html的正文是:

<body>

<h1>Find User:</h1>
<form th:object="${user}" th:action="@{finduser}"  method="post">
    <p>Find by ID: <input type="text" th:field="*{id}" /></p>
    <p><input type="submit" value="Submit" /></p>
</form>

</body>

查找用户:
按ID查找:

我应该更改什么来将id从视图传递到我的控制器,以便我的控制器可以使用id并搜索用户

我认为id必须通过url传递,因为


@RequestMapping(value=“finduser/{id}”…)

您可以指定表单
操作
():

还可以包括路径变量形式的参数 与普通参数类似,但在内部指定占位符 您的URL路径:

在您的情况下,您可以这样做,例如:

或者,如果您希望在变量中包含url: