angular js 删除及多条删除

一、编写service

    //删除
    public int delete(Long id);
    //多条删除
    public int deletes(List<Long> id);

二、编写serviceImpl

    @Override
    public int delete(Long id) {
        return brandDao.deleteByPrimaryKey(id);
    }

    @Override
    public int deletes(List<Long> id) {
        if(id!=null){
            for (Long ids:id){
                brandDao.deleteByPrimaryKey(ids);
            }
        }
        return 0;
    }

三、编写controller

    //删除
    @RequestMapping("/deletes")
    public Result deletes(@RequestBody List<Long> id){
        int ids = brandService.deletes(id);
        if(ids>0){
            return new Result(true,"删除成功");
        }else {
            return new Result(true,"删除失败");
        }
    }

四、编写页面

 1、编写angular js      
       //
定义一个集合储存选中的ID $scope.selectID=[]; //给复选框一个点击事件,如果勾选,则把勾选的ID存入$scope.selectID=[]集合中 //如果取消勾选,则把存入$scope.selectID=[]集合的ID从集合中移除 $scope.saveID=function ($event,id) { //如果勾选,则把勾选的ID存入$scope.selectID=[]集合中 if ($event.target.checked){ //往集合中添加数据,用push $scope.selectID.push(id); }else { //获取ID在集合中下标 var index=$scope.selectID.indexOf(id); //移除对应下标的数据,splice表示将集合中对应下标的数据移除一次 $scope.selectID.splice(index,1); } //页面控制台打印选中的数据 console.log($scope.selectID); } $scope.deletes=function () { $http.post('../brand/deletes.do',$scope.selectID).success(function (response) { if(response.success){ return $scope.reloadList(); }else { alert(response.message); } }); }
二、body标签加入angularjs:
<body class="hold-transition skin-red sidebar-mini" ng-app="pingyougou" ng-controller="brandController">
三、页面复选框标签加angular
<td><input ng-click="saveID($event,entity.id)" type="checkbox" ></td>
四、删除按钮调用angular js删除方法
<button type="button" class="btn btn-default" title="删除" ng-click="deletes()"><i class="fa fa-trash-o"></i> 删除</button>

 
原文地址:https://www.cnblogs.com/zhangrongfei/p/11347259.html