Thymeleaf - 使用确认模式删除

问题描述 投票:1回答:1

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

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>

调节器

@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";
}
java spring web thymeleaf
1个回答
0
投票

我发现了错误:我替换为:

th:attr="data-target='#myModal'+${fgp.fingerprintId}">D</button> 

th:attr="id='/home/'+${fgp.fingerprintId}+'/deleteFingerprints'"> 
© www.soinside.com 2019 - 2024. All rights reserved.