加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

从泽西返回JSONP

发布时间:2020-12-16 19:52:05 所属栏目:百科 来源:网络整理
导读:我目前正在使用泽西返回 JSON.如何返回 JSONP?例如,我目前的RESTful方法是: @GET@Produces(MediaType.APPLICATION_JSON)public ListOrder getOrders() { return OrderRepository.getOrders();} 我想在Tomcat上部署(不想要使用GlassFish).我唯一的依赖泽西
我目前正在使用泽西返回 JSON.如何返回 JSONP?例如,我目前的RESTful方法是:
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Order> getOrders() {
    return OrderRepository.getOrders();
}

我想在Tomcat上部署(不想要使用GlassFish).我唯一的依赖泽西是:

<dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.9.1</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.9.1</version>
    </dependency>

需要什么额外的依赖代码如何改变?

谢谢.
纳雷什

看看泽西州的 JSONP示例(特别是 ChangeList资源)(您可以下载整个项目 here).

你基本上需要做的就是这样:

@GET
@Produces(MediaType.APPLICATION_JSON)
public JSONWithPadding getOrders() {
    return new JSONWithPadding(new GenericEntity<List<Order>>(OrderRepository.getOrders()){});
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读