angularjs + springMVC实现删除

(1)定义interface:

//删除,选中多个单选框

public void delete(Long[] ids); 

(2)定义service:

@Override
public void delete(Long[] ids) {
for(Long id:ids){// 循环遍历数组进行删除
brandMapper.deleteByPrimaryKey(id);
}

}

(3)定义Controller:

@RequestMapping("/delete")
public Result delete(Long[] ids){////注:这里是Long,不是long,接受从前端传递进来的列表,如:[1,2,3],不然会发生500错误
try{
brandService.delete(ids);
return new Result(true, "删除成功");
}catch(Exception e){
System.out.println("删除时出现异常:" + e.getMessage());
return new Result(false, "删除时出现异常:" + e.getMessage());
}

}

(4)定义前端页面核心代码:

                $scope.ids = [];
//即将实现商标条目的删除
$scope.selectOption = function($event, id){
if($event.target.checked){
$scope.ids.push(id);//将id追加到列表后面
}else{
var index = $scope.ids.indexOf(id);
$scope.ids.splice(index, 1); //取出指定的1个元素
}
}

$scope.dele = function(){
//alert($scope.ids);
$http.get("../brand/delete.do?ids=" + $scope.ids).success(
function(response){
if(response.success){
$scope.reloadPage();//重新加载页面中的数据
}else{
alert(response.message);
}
}
);

}

<button type="button" class="btn btn-default" title="删除" ng-click="dele()">
<i class="fa fa-trash-o"></i> 删除

</button>

<td><input type="checkbox" ng-model="selectedBox" ng-click="selectOption($event, entity.id)"></td>

猜你喜欢

转载自blog.csdn.net/jiuweideqixu/article/details/80659592