Thymeleaf 中是否可以有变量的输入路径
我知道标题可能会产生误导,但我的问题是:在 Thymeleaf 中,我们使用输入(在 HTML 中)设置请求参数。是否可以有一个设置路径变量的输入字段。例如,我有一个这样的方法:
@PostMapping("/house/{id}/rent")
public String rentHouse(@RequestParam Date startDate, @PathVariable("id") long id, Model model) {
House h = new House();
h.setId(id);
r.setStartDate(startDate);
Rents rents = rentsService.createNewRent(h, id);
model.addAttribute("rent", rents);
return "House";
}
在 House.html 中,我想要这样的内容:
<form th:action="@{/house/${id}/rent/}" method="post">
<label for="startDate">start Date:</label><br>
<input type="datetime-local" id="startDate" th:name="startDate" placeholder="startDate"><br>
<label for="id">house id:</label><br>
<input type="number" id="id" th:name="id" placeholder="id"><br>
<br>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
这样,当我输入某些内容时,结果 url 应该如下所示(我知道开始日期的格式错误): localhost:8080/House/12/rents?startDate=02.21.22
是否也可以在 Thymeleaf 中传递请求正文,我搜索了类似的问题,但他们都通过手动将路径变量放入 url 中来解决它。 提前致谢
I know the title might be misleading but here my question: In Thymeleaf we set request params with the input (in HTML). Is it possible to have an input field that sets the path variable. For example I have an method like this:
@PostMapping("/house/{id}/rent")
public String rentHouse(@RequestParam Date startDate, @PathVariable("id") long id, Model model) {
House h = new House();
h.setId(id);
r.setStartDate(startDate);
Rents rents = rentsService.createNewRent(h, id);
model.addAttribute("rent", rents);
return "House";
}
And in House.html I want something like this:
<form th:action="@{/house/${id}/rent/}" method="post">
<label for="startDate">start Date:</label><br>
<input type="datetime-local" id="startDate" th:name="startDate" placeholder="startDate"><br>
<label for="id">house id:</label><br>
<input type="number" id="id" th:name="id" placeholder="id"><br>
<br>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
So that when I input something then the result url should be looking like this (I know start Date has false format):
localhost:8080/House/12/rents?startDate=02.21.22
And is it also possible to pass request body in Thymeleaf, I searched for similar questions but they all solved it by manually putting the path variable in the url.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论