2016-10-25 58 views
0

我正在從AngularJS調用一個Spring API,在那裏我試圖傳遞一個模型對象列表作爲參數。將AngularJS的列表傳遞給Spring Controller

data.append('updatedItems', $scope.QuoteList); 
$http.post('updateQuotes', data).success(function(response) { 
    console.log(response); 
}); 

然後在春天控制器,我想如下接收

@RequestMapping(value = "/updateQuotes", method = RequestMethod.POST) 
public ArrayList<ConsumerPrice> updateQuotes(@RequestBody List<ConsumerPrice> updatedItems, ConsumerPrice consumerPrice) { 
    System.out.println(updatedItems); 
    return null; 
} 

在這一點上,我得到一個異常如下所述。我不確定這是否是從Angular向Spring控制器傳遞列表的正確方法。

Invalid mime type "application/json;charset=utf-8, multipart/form-data; 

我在互聯網上發現了很少的指導,並嘗試像提供消費標題,但沒有任何幫助。任何指導意見將是巨大的

我想在春天控制器,但沒有幫助

+0

我跟着一個建議並創建了一個包裝類如下所示 公共類ConsumerPriceWrapper { \t列表 listConsumerPrice; } 然後在Spring控制器中,我添加了如下但仍然不起作用 public ArrayList updateQuotes(@RequestBody ConsumerPriceWrapper updatedItems,ConsumerPrice consumerPrice) – CrazyMac

回答

0

最後我能解決這個提供@PathVariable。 Spring控制器中沒有任何東西,但我改變了從Angular控制器傳遞Javascript數組的方式。

下面的第2行是關於如何將列表添加到formdata數組的差異。這幫助我在Spring Controller中獲取值。

$scope.formData = []; 
$scope.formData = $scope.cQuoteList; 
$http.post('updateQuotes', $scope.formData).success(function(response) { 
     $scope.userQuotes(); 
}); 
相關問題