胸腺生成无查询参数的URL,但是?出现
我正在使用 Thymeleaf
开发一个简单的 Spring Boot MVC 应用程序
。
thymeleaf 部分代码:
<tr th:each="dept: ${departments}">
<td th:text="${dept.getId()}"></td>
<td th:text="${dept.getName()}"></td>
<td>
<form th:object="${dept}" th:action="@{'/departments/' + ${dept.getId()}}">
<button class="btn btn-secondary">Details</button>
</form>
</td>
<td>
<form th:object="${dept}" th:action="@{/departments/{id}/edit(id=${dept.getId()})}">
<button class="btn btn-secondary">Edit</button>
</form>
</td>
<td>
<form th:object="${dept}" th:action="@{/departments/{id}(id=${dept.getId()})}" th:method="delete">
<button class="btn btn-secondary">Delete</button>
</form>
</td>
</tr>
UI 界面如下所示:
单击编辑
按钮时(详细信息
按钮也是如此),它加载正确,但 URL 为其他查询参数生成 ?
字符,但实际上没有(例如 http://localhost:8089/departments/3/edit?
)。
控制器代码是:
@GetMapping("/{id}/edit")
public String editDepartment(@PathVariable("id") String departmentId, Model model) {
var department = departmentService.getDepartmentById(Long.valueOf(departmentId));
model.addAttribute("department", department);
return "edit-department"; // returns view
}
我的问题是正在显示的 ?
字符。我不希望它出现,因为没有查询参数。有什么帮助吗?
I'm working on a simple Spring Boot MVC application
using Thymeleaf
.
Part of the thymeleaf code:
<tr th:each="dept: ${departments}">
<td th:text="${dept.getId()}"></td>
<td th:text="${dept.getName()}"></td>
<td>
<form th:object="${dept}" th:action="@{'/departments/' + ${dept.getId()}}">
<button class="btn btn-secondary">Details</button>
</form>
</td>
<td>
<form th:object="${dept}" th:action="@{/departments/{id}/edit(id=${dept.getId()})}">
<button class="btn btn-secondary">Edit</button>
</form>
</td>
<td>
<form th:object="${dept}" th:action="@{/departments/{id}(id=${dept.getId()})}" th:method="delete">
<button class="btn btn-secondary">Delete</button>
</form>
</td>
</tr>
The UI interface looks like this:
When clicking on the Edit
button (same goes for the Details
one), it loads correctly, but the URL generates the ?
character for other query parameters, but there are actually none (for example http://localhost:8089/departments/3/edit?
).
The controller code is:
@GetMapping("/{id}/edit")
public String editDepartment(@PathVariable("id") String departmentId, Model model) {
var department = departmentService.getDepartmentById(Long.valueOf(departmentId));
model.addAttribute("department", department);
return "edit-department"; // returns view
}
My problem is with the ?
character that is being displayed. I don't want it to appear as there are no query parameters. Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它添加了一个问题
?
因为您正在提交一个空表单。为什么不直接使用按钮样式的链接呢?It's adding a question
?
because you are submitting an empty form. Why not just use a link styled as a button?尝试
Try