415不支持的媒体类型
问题描述:
我试图使用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;
答
按照沿着上面评价本身解释ction,obj由所有提交并传递给控制器的表单参数组成。
JSP HTML标签:
<input type="text" ng-model="obj.balcony" />
<input type"text" ng-model="obj.address" />
并在控制器,请尝试使用警报调试对象价值和转换成字符串对象使用 'JSON.Stringify(OBJ)'。
控制器JS:
$scope.submit = function() {
var formData = $scope.obj;
alert(JSON.stringify($scope.obj));
var response = $http.post('/PM/insp_rep/{id}', JSON.Stringify(obj));
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>
问题是在你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