1.html
<table id="tab" class="table table-hover table-striped">
<tr>
<th><input type="checkbox" class="bs-checkboxAll" id="selectAll" name="btSelectAll" onclick="btSelectAllOnclick(this)"></th>//复选框 点击btSelectAllOnclick,this获取当前复选框
<th>序号</th><th>项目编号</th>
</tr>
<tr th:each="list:${checkCarPropertiesList}" id="delTr" th:value="${list.id}">
<td><input type="checkbox" th:value="${list.id}" class="bs-checkbox" name="btSelectItem"></td>//复选框
<td th:text="${list.id}" id="idNum" th:value="${list.id}" name="id" readonly></td>
<td th:text="${list.number}" th:value="${list.number}" name="number" style></td>
</tr>
</table>
2.js
// 全选复选框 (btSelectAllOnclick,与前台的input标签中onclick点击的方法名相同,其他不用改)
function btSelectAllOnclick(checkbox) {
var flage = $(checkbox).is(":checked");
if(flage){
$("#tab td input").prop("checked", true);
}else {
$("#tab td input").prop("checked", false);
}
}
// 删除
function deleteCarAttribute() {
var ids = [];
$.each($("input[class=bs-checkbox]:checked"),function(){ //属性选择器,选择器定位到input标签中class=bs-checkbox,获取所有点选的复选框
ids.push($(this).val());//将点选的复选框全放进ids数组中
});
alert("要删除的id=========="+ids);
$.getJSON("/repaircar/checkCarProperties/batchRemove","ids="+ids,del)
function del(data) {
$("#tab td :checkbox").each(function() {
if ($(this).prop("checked") === true) {
$(this).parents('tr').remove()
}
});
}
}
3.controller
@GetMapping( "/batchRemove")
@ResponseBody
public R remove(@RequestParam("ids") Long[] ids){
if(checkCarPropertiesService.batchRemove(ids)>0){
return R.ok();
}
return R.error();
}
4.Dao接口
int batchRemove(Long[] ids);
5.Dao实现类
(批量删除,数组)
<delete id="batchRemove">
delete from repair_check_car_properties where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
亚磊的一对对,批量添加
1.controller
//
@ResponseBody
@PostMapping("/save")
public R save(PartsManagementBuyingDO partsManagementBuying){ //对象里面有集合(一对多)
List<ChooselistingDO> chooseList = partsManagementBuying.getChoose();
for(int i = 0; i < chooseList.size(); i++){ //给两表关联字段赋值
chooseList.get(i).setProductlistnumber(partsManagementBuying.getId());
}
if(partsManagementBuyingService.save(partsManagementBuying,chooseList)>0){
return R.ok();
}
return R.error();
}
2.service实现类
(参数是两个,一个是主表,一个是主表里的集合所在的表)
@Transactional(rollbackFor=Exception.class)
@Override
public int save(PartsManagementBuyingDO partsManagementBuying, List<ChooselistingDO> chooselistingDOList){
if(partsManagementBuyingDao.save(partsManagementBuying) > 0){
return chooselistingDao.save(chooselistingDOList);
}
return 0;
}
3.Dao接口
int save(List<ChooselistingDO> chooselistingDOList);
4.Dao实现类
(批量增加,集合)
<insert id="save">
insert into common_chooselisting
(
`productId`,
`productListNumber`,
`number`,
`money`,
`remark`
)
values
<foreach item="chooselistingDOList" collection="list" separator=",">
(
#{chooselistingDOList.productid},
#{chooselistingDOList.productlistnumber},
#{chooselistingDOList.number},
#{chooselistingDOList.money},
#{chooselistingDOList.remark}
)
</foreach>
</insert>