我想从表中删除该对象。问题是我没有删除我点击的对象。我总是删除上面的对象。我究竟做错了什么?
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">×</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>
调节器
@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";
}
我发现了错误:我替换为:
th:attr="data-target='#myModal'+${fgp.fingerprintId}">D</button>
与
th:attr="id='/home/'+${fgp.fingerprintId}+'/deleteFingerprints'">