gpt4 book ai didi

java - Thymeleaf - 使用确认模式删除

转载 作者:行者123 更新时间:2023-11-30 06:16:50 26 4
gpt4 key购买 nike

我想从表中删除该对象。问题是我没有删除我单击的对象。我总是删除上面的对象。我做错了什么?

home.html

<tr th:each="fgp : ${fingerprints}">
<td><a th:href="@{'/home/'+${fgp.fingerprintId}+'/viewFingerprints'}"><button
type="button" class="btn btn-success">V</button></a> <a
th:href="@{'/home/'+${fgp.fingerprintId}+'/editFingerprints'}"><button
type="button" class="btn btn-warning">E</button></a>

<button type="button" class="btn btn-danger" data-toggle="modal"
data-target="#myModal"></button>

<!-- The Modal -->
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">

<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Are you sure?</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>

<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger"
data-dismiss="modal">Close</button>
<a th:href="@{'/home/'+${fgp.fingerprintId}+'/deleteFingerprints'}"><button
type="button" class="btn btn-success">Yes</button></a>
</div>
</div>
</div>
</div>
</td>

Controller

@GetMapping("/home/{fingerprintId}/deleteFingerprints")
public String deleteFingerprints(@PathVariable("fingerprintId") int id, Model model) {

Fingerprints fingerprint = fingerprintRepository.findByFingerprintId(id);

System.out.println("Fingerprint id: " + fingerprint.getFingerprintId());

fingerprintRepository.delete(fingerprint);

return "redirect:/home";
}

最佳答案

<tr th:each="record : ${recordList}" >              
<td>
<button type="button" class="btn btn-outline-light text-dark" data-toggle="modal" th:attr="data-target='#recordDeleteModal'+${record.id}">Delete</button>

<!-- Modal -->
<div class="modal fade" th:attr="id='recordDeleteModal'+${record.id}" tabindex="-1" role="dialog" aria-labelledby="recordDeleteModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="recordDeleteModalLabel">Delete Record</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
Are you sure you want to delete this record?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
<a href="newRecordForm.html" class="btn btn-primary" th:attr="href='/record/'+${record.id}+'/deleteRecord'">Yes</a>
</div>
</div>
</div>
</div>
<!-- Modal end -->

</td>

关于java - Thymeleaf - 使用确认模式删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49009822/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com