2015-10-15 43 views
0

我想用$ http delete从数据库中删除一个产品,但我不能,因为我无法恢复表中元素的id。用angularjs删除查询

代码: 丹斯乐controlleur:

@RequestMapping("/delete") 

public boolean deleteProduit(Long Id) 

{ 
produitRepository.delete(Id); 
return true; 
} 

丹斯html页面:

<td >{{p.id}}</td> 
<td>{{p.name}}</td> 
<td>{{p.price}}</td> 
<td> 
<a class='btn btn-danger' href='' ng-click='supprim(produits.content)'> 
Delete 
</a> 

丹斯JS:

$scope.supprim = function(data){ 
$scope.produits.content=data; 

var index = $scope.produits.content.indexOf(data); 
var result = confirm('Are you sure to delete this product ? '); 

if(result===true) 
{ 
alert($scope.produits.content.valueOf(id)) 

$http.delete("/delete?Id="+$scope.produits.content.id); 
        $scope.produits.content.splice(index, 1); 
} 
}; 

拉页JSON ES t sous cette forme

{“content”:[{“id”:5,“name”:“pk25”,“price”:125.0},{“id”:6,“name”:“ PK25" , “价格”:125.0},{ “ID”:7, “名称”: “PK25”, “价格”:125.0},{ “ID”:8中, “名称”: “PK25”, “价格” :125.0},{ “ID”:9 “名称”: “PK25”, “价格”:125.0}], “总页数”:2 “totalElements”:9 “最后”:假, “尺寸”:5 , “数字”:0, “第一”:真正的 “排序”:空, “numberOfElements”:5}

我需要帮助

+0

欢迎堆栈溢出。我编辑了你的帖子来解决英文问题和格式。 –

回答

0

您必须使用控制器@ResponseBody anotation。所以你的代码就像这样。 此代码不完整。 春季控制器代码

@RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE) 
    @ResponseBody 
    public void delete(@PathVariable("id") Long id){  
    } 

和你angularjs这样的代码

 var response = $http.delete('/delete/' + id) 
      response.success(function (data, status, headers, config) { 
      }); 
      response.error(function (data, status, headers, config) { 
       alert('Error deleting ...'); 
      }); 
+0

问题出在这行$ http.delete('/ delete /'+ id) –

+0

这个id在undefined中。我如何恢复身份证 –