【发布时间】:2022-01-31 00:16:02
【问题描述】:
我是 spring 新手,我需要能够通过复选框删除选定的行。如何从数据库中删除多行?我使用 Thymeleaf 作为视图。
这是我的代码:
HTML
<div class="col-md-12">
<table class="table" id="tableImport">
<thead>
<tr>
<th scope="col">Remove</th>
<th scope="col">Debt Age Rule</th>
<th scope="col">Reminder</th>
<th scope="col">Frequency</th>
<th scope="col">Reorder</th>
</tr>
</thead>
<tbody>
<tr th:each="configCampaign:${listConfigCampaigns}">
<td>
<input type="checkbox" name="my-checkbox">
</td>
<td th:text="${configCampaign.debtagerule}"></td>
<td th:text="${configCampaign.remindebttype}"></td>
<td th:text="'Every '+${configCampaign.every} + ' ' + ${configCampaign.unit}"></td>
<td></td>
</tr>
</tbody>
</table>
<div class="col-md-12" style="text-align: center">
<input class="btn btn-primary" type="button" value="- Remove Selected Action(s)"/>
</div>
</div>
此表显示来自内存中 arrayList 的数据,没有数据库,我需要从数组中删除那些选定的对象。目前我有这样的控制器
实体
private int configid;
private String debtagerule;
private String remindebttype;
private int every;
private String unit;
private boolean selected;
//getters and setters
除了上述之外,这是我目前正在使用的控制器
控制器
@GetMapping("/deleteConfigureCampaign")
public String deleteConfig(@ModelAttribute ConfigCampaign configCampaign, Model model) {
listConfigCampaigns.remove(configCampaign);
return "redirect:/configureCampaign";
}
【问题讨论】:
-
你的
Controller和Service在哪里。从数据库中删除项目或从页面中临时删除? -
@GetMapping("/deleteConfigureCampaign") public String deleteConfig(@ModelAttribute ConfigCampaign configCampaign, 模型模型) { listConfigCampaigns.remove(configCampaign);返回“重定向:/configureCampaign”; } 这是我的控制器,想法是删除临时对象
-
回答正确请采纳
标签: java spring-boot thymeleaf