前端穿的参数应该是个参数的数组进行批量操作,所以传的字段设置为:long[] 传的字段
controller层
@RequestMapping(value = "/deleteXZ", method = RequestMethod.POST)
public RestResult> deleteXZProducts(Long[] xxx){
RestResult> result = new RestResult<>();
try {
loanProductsService.deleteXZProducts(xxx);
result.setCode(RestResult.SUCCESS);
result.setMessage("操作成功");
} catch (BusinessException e) {
result.setCode(RestResult.FAIL);
result.setMessage(e.getMessage());
}
return result;
}
int deleteXZProducts(Long[] xxx) throws BusinessException;
实现层:
@Override
@Transactional
public int deleteXZProducts(Long[] xxx) throws BusinessException {
if(Validator.isNull(xxx)) {
throw new BusinessException("选择删除的数据不能为空!");
}
return loanProductsMapper.updateXZProducts(xxx);
}
int updateXZProducts(@Param("list")Long[] xxx);
这里的sql是进行的逻辑删除(假删)仅供参考
update 表名 set 字段(逻辑删除)= 1 where xxx(前端传来的字段) IN
#{xxx, jdbcType=BIGINT}
前端说明:这里我用的是angular,设计上的逻辑是个菜单按钮,所以这个html没有这个按钮设计,只有获取到数据的p-table下的
[(selection)]="selectedLoanProductsData" 来进行获取选择的数据component层
提供一个component下的接口逻辑:
onDetailXZ () {
if (this.selectedLoanProductsData === null || this.selectedLoanProductsData.length < 1) {
this.messageService.add({severity: 'info', detail: '请选择要删除的记录'});
} else {
this./confirm/iationService.confirm({
message: '你确认删除所选记录吗?',
header: '删除确认',
icon: 'pi pi-info-circle',
acceptLabel: '确定',
rejectLabel: '取消',
accept: () => {
let list: number[] = [];
this.selectedLoanProductsData.forEach((xxx, index, array) => {
list.push(xxx.loanProductsId);
});
this.loanProductsService.deleteXZProducts(list).subscribe(value => {
const resp = value as GeneralResponse;
if ('0' === resp.code) {
this.messageService.add({severity: 'success', detail: resp.message});
this.onRefresh();
} else {
this.messageService.add({severity: 'error', detail: resp.message});
}
});
}
});
}
}
service层
deleteXZProducts(xxx: number[]) {
return this.http.post(this.config.getContextPath() + '/.../deleteXZ', { xxx: xxx});
}
这是整个代码逻辑,互相提供帮助



