Когда я делаю проект с jsp, я стараюсь сделать его простым.Теперь я хотел сделать проект в Thymeleaf.Я хотел показать диалоговое окно подтверждения перед удалением.Я это сделал.Но пока я нажимаю ОК, я получаю сообщение об ошибке.Я думаю, что не могу правильно установить ссылку внутри метода onclick
.
Вот мой HTML-код:
<tr th:each="student,iterStat : ${studentList}">
<td th:text="${student.id}"></td>
<td th:text="${student.roll}"></td>
<td th:text="${student.firstName}"></td>
<td th:text="${student.lastName}"></td>
<td th:text="${student.age}"></td>
<td>
<!-- <a th:href="@{/deleteStudent/(id=${student.id})}">Delete</a> -->
<a href="#" onclick="confirmRemoveQuestion('@{/deleteStudent/(id=${student.id})}')">
Delete
</a>
</td>
<script>
function confirmRemoveQuestion(link) {
if (show_confirm()) {
window.location = link;
this.hide();
} else {
this.hide();
}
}
function show_confirm() {
return confirm("Are you sure you want to do this?");
}
</script>
</tr>
Вот мой контроллер:
@RequestMapping(value = "/deleteStudent", method = RequestMethod.GET)
public String deleteStudent(@RequestParam(name="id") int id) {
studentService.deleteStudent(id);
return "redirect:/getStudents";
}
Примечание: без диалогового окна я могу легко удалить объект.Этот код находится в строке комментария.