415不支持的媒体类型与Spring MVC和REST服务 [英] 415 Unsupported Media Type with Spring MVC and Rest Service

查看:533
本文介绍了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

请求URL是:

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;
}

我的角度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'}
    })};

}]);

code在我controller.js其中makea电话:

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) {

这篇关于415不支持的媒体类型与Spring MVC和REST服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆