我有一个简单的and应用程序,显示学生列表和添加和删除按钮,如下所示:

index.html - table
<tr th:each="student : ${students}">
<td th:text="${student.firstName} + ' ' + ${student.lastName}"></td>
<td th:text="${student.email}"></td>
<td th:text="${student.department}"></td>
<td><a th:href="@{/delete/{id}(id=${student.id})}" class="btn btn-danger">Delete</a></td>
</tr>IndexController.java -用于删除
@GetMapping("/delete/{id}")
public String deleteStudent(@PathVariable Long id)
{
studentService.deleteStudentById(id);
return "redirect:/";
}我的问题--为什么我的控制器中必须有@GetMapping才能删除在www页面上使用删除按钮的学生?当我有@DeleteMapping的时候(正如我想的那样),我不能删除一个在www页面上有删除按钮的学生。有一个405 error在做它,但通过邮递员选择删除方法,我可以删除它。
发布于 2019-07-29 13:59:48
@DeleteMapping注释需要一个th:=“删除”才能工作。
<td>
<form th: action = "@ {/delete/{id}(id=${student.id})}" th: method = "delete" >
<input class = "btn btn-default btn-xs" type = "submit" = Valeur "Supprimer" />
</ form>
</td>https://stackoverflow.com/questions/57254807
复制相似问题