我試圖使用Spring Restful Web服務將數據保存到數據庫。415不支持的媒體類型
我在郵遞員中運行此代碼時不斷得到不受支持的媒體類型錯誤。
我已經編輯我的前端JSP代碼和庫類代碼..
我還添加了pom.xml文件傑克遜依賴。我無法弄清楚我的代碼有什麼問題,因爲我是Restful Web服務的新手。
控制器::
@RequestMapping(value="/insp_rep/{id}",method=RequestMethod.POST, headers = "Accept=application/json")
ResponseEntity <Void> addRepo(@RequestBody PC_Repo report, @PathVariable("id") int id){
this.pmService.addRep(report);
return new ResponseEntity<Void>(HttpStatus.CREATED);
}
JSP代碼與AngularJS腳本
<html data-ng-app="formSubmit">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('formSubmit', []);
app.controller('FormSubmitController',[ '$scope', '$http', function($scope, $http) {
$scope.list = [];
$scope.headerText = 'Inspection Report';
$scope.submit = function() {
var formData = {
"ins_id": $scope.ins_id,
"date_insp": $scope.date_insp,
"bedrooms":$scope.bedrooms,
"balcony":$scope.balcony,
"kitchen":$scope.kitchen,
"bath_toilet":$scope.bath_toilet,
"parking_gar":$scope.parking_gar,
"garden":$scope.garden,
"others":$scope.others,
"action":$scope.action
};
var response = $http.post('/PM/insp_rep/{id}', formData);
response.success(function(data, status, headers, config) {
$scope.list.push(data);
});
response.error(function(data, status, headers, config) {
alert("Exception details: " + JSON.stringify({data: data}));
});
//Empty list data after process
$scope.list = [];
};
}]);
</script>
repository類
@Entity
@JsonIgnoreProperties({"hibernateLazyInitializer","handler"})
@Table(name="abc")
public class abc implements Serializable {
private java.sql.Date date_insp;
private String bedrooms;
private String balcony;
private String kitchen;
private String bath_toilet;
private String parking_gar;
private String garden;
private String others;
private String title;
private byte[]photo;
問題是在你request.It相關看來你是不以正確的JSON format.Check發送請求的依賴就像傑克遜出現在類路徑或沒有。 – Vaibs
嗨Vaibs,謝謝你的答..我已經在pm.xml文件中添加了依賴項。請讓我知道,如果我添加了一個錯誤的依賴......我添加的依賴關係是: \t \t com.fasterxml.jackson.core \t \t 傑克遜,數據綁定 \t \t 2.4.1 \t \t –
Pra
它似乎correct.check現在 – Vaibs