在Jersey Rest中使用@Consume和GET请求 [英] Using @Consume with GET request in Jersey Rest

查看:1211
本文介绍了在Jersey Rest中使用@Consume和GET请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将GET请求中的值绑定到POJO。

I'm trying to bind values in a GET request to a POJO.

这些值是HTTP GET请求中的参数。我正在使用JSONP传递参数,但看起来JSONP将JSON对象推送到Request行,因此它实际上不是正在发送的JSON对象,而只是在URL上命名值对。

The values are parameters in a HTTP GET request. I'm using JSONP to pass the parameters however it looks like JSONP pushes the JSON object up onto the Request line so its not really a JSON object which is being sent but instead just name value pairs on the URL.

是否可以将我的GET请求中的值映射到POJO?当我尝试绑定时,Jersey会给出以下异常

Is it possible to map the values in my GET request to a POJO? Jersey gives the following exception when i try binding

HTTP GET方法public void handleJSONP(MyPojo)不应该使用任何实体。

A HTTP GET method, public void handleJSONP(MyPojo), should not consume any entity.

绑定代码在请求体中查找,但它不存在,因为它是一个GET请求。是否有任何其他方法来绑定请求中的值而无需为每个值手动包含@QueryParam条目?

The binding code is looking in the request body however it doesnt exist because it is a GET request. Is there any other way to bind the values in the request without having to manually include a @QueryParam entry for each ?

谢谢

推荐答案

我能够通过@com.sun.jersey.api.core.InjectParam

public JSONWithPadding doSomething(@InjectParam final MyPojo argPojo) 

然后Pojo看起来像这样

Then the Pojo looks like this

public class MyPojo 
{
/** */
@QueryParam("value1")
private String value1;

/** */
@QueryParam("value2")
private String value2;

/** */
@QueryParam("value3")
private List<String> value3;

这篇关于在Jersey Rest中使用@Consume和GET请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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