I have a simple webapp showing list of students with add and delete button like this:
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 - for deleting
@GetMapping("/delete/{id}")
public String deleteStudent(@PathVariable Long id)
{
studentService.deleteStudentById(id);
return "redirect:/";
}
My question - why it has to be @GetMapping
in my controller that will delete a student using Delete button on the www page? When I had @DeleteMapping
there (as I thought it should be) I couldn't delete a student with Delete button on the www page. There was a 405 error
while doing it but via Postman with delete method selected I could delete it.