我試圖更新一些數據使用$ http.post方法從angularjs到Spring MVC控制器。但是,由於「HTTP狀態405 - 請求方法'GET'不支持」而出現錯誤。我的代碼片段,如下:
// AngularJS服務
updateData : function(data) {
return $http.post('updateData', data).then(
function(response){
// success callback
return response;
},
function(response){
// failure callback
return response;
}
);
}
,其中數據是如下:
數據= [{ ID:1, 名: '富' }, { id:2, name:'bar' },{ id:3, name:'baz' }];
// Spring MVC的控制器代碼
@RequestMapping(value="/updateData", method = RequestMethod.POST)
public @ResponseBody String updateData(@RequestBody Company company) throws Exception {
// I have created POJO for company with id and name getter-setter
// logic to update the data in db
//System.out.println(company.getName());
return "success";
}
我的代碼中的任何錯誤?
我會在你的JS代碼的'updateData'前添加'/',並通過F12網絡選項卡檢查請求實際發送到哪個URL。您的Java代碼看起來不錯,因此應該按預期工作。 –
好的 - 讓我試試 – Sowmya
否.....在updateData前面添加/會給我404錯誤。 – Sowmya