415 不支持的媒体类型与 Spring MVC 和 Rest 服务
问题描述:
我得到了
415 Unsupported Media Type - The server refused this request because the request entity is in a format not supported by the requested resource for the requested method
请求网址为:
http://localhost:8080/ngdemo/web/posts/review/80a5d7660cdb82a8ef9f8db79bb3c8ab14555377
从弹簧控制器读取时出错;我检查了我的其他相同模式的控制器方法,它们工作正常,但不是我新引入的.我找不到它的任何问题,你能建议我缺少什么吗?
error while reading from spring controller; I checked with my other controller methods of same pattern and they are working fine but not this one which I newly introduced. I cant find any issue with it, can you please suggest whats I am missing?
我的控制器:
@RequestMapping(value = "/review/{key}", method = RequestMethod.GET, consumes = "", produces = "application/json")
public
@ResponseBody
List<Review> reviews(@PathVariable(value = "key") String key) {
System.out.println("key : " + key);
List<Review> reviewList = reviewService.getReviewsById(key);
System.out.println("reviewList : " + reviewList.size());
return reviewList;
}
我的 Angular Services.js:
My Services.js of Angular:
services.factory('PostFactory', ['$resource', function ($resource) {
alert("I am here service");
return {
postmain: $resource('/ngdemo/web/posts', {}, {
query: {method: 'GET', isArray: true },
create: {method: 'POST'}
}),
reviews: $resource('/ngdemo/web/posts/review/:key', {}, {
query: {method: 'GET', params: {key: '@key'} },
create: {method: 'POST'}
}),
postreview: $resource('/ngdemo/web/posts/getreview', {}, {
query: {method: 'GET', isArray: true },
create: {method: 'POST'}
}),
allresults: $resource('/ngdemo/web/posts/result/:tag', {}, {
query: {method: 'GET', params: {tag: '@tag'} },
create: {method: 'POST'}
})};
}]);
在我的 controller.js 中进行调用的代码:
Code in my controller.js which makea call:
var reviewId = place.id;
$scope.allreviews = PostFactory.reviews.query({key: reviewId})
我找不到问题出在哪里,所以请你们看看并指出我遗漏了什么?谢谢!
I cant find where the issue is, so can you guys please have a look and point me what is that which I missed? Thanks!
答
它通过添加:
@Consumes("text/html")
@Consumes("text/html")
@RequestMapping(value = "/review/{key}", method = RequestMethod.GET, produces = "application/json")
public
@ResponseBody
List<Review> reviews(@PathVariable(value = "key") String key) {