栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot+前端angular批量删除功能实现

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot+前端angular批量删除功能实现

后端代码实现 后端逻辑:

前端穿的参数应该是个参数的数组进行批量操作,所以传的字段设置为: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;
    }

service层及service实现层

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);
    }

mapper层及对应的sql语句层

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});
}

这是整个代码逻辑,互相提供帮助

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/348904.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号