jersey 示例获取List<Object>(二)
来源:互联网 发布:360强制修复网络 编辑:程序博客网 时间:2024/06/05 20:04
1. bean 代码
package com.base.pf.restful.client;import java.io.Serializable;import javax.xml.bind.annotation.XmlAccessType;import javax.xml.bind.annotation.XmlAccessorType;import javax.xml.bind.annotation.XmlElement;import javax.xml.bind.annotation.XmlRootElement;@XmlRootElement@XmlAccessorType(XmlAccessType.FIELD)public class Podcast implements Serializable {private static final long serialVersionUID = -8039686696076337053L;@XmlElement(name = "id")private Long id;@XmlElement(name = "title")private String title;@XmlElement(name = "linkOnPodcastpedia")private String linkOnPodcastpedia;@XmlElement(name = "feed")private String feed;@XmlElement(name = "description")private String description;public Podcast(String title, String linkOnPodcastpedia, String feed,String description) {this.title = title;this.linkOnPodcastpedia = linkOnPodcastpedia;this.feed = feed;this.description = description;}public Podcast() {}public Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public String getLinkOnPodcastpedia() {return linkOnPodcastpedia;}public void setLinkOnPodcastpedia(String linkOnPodcastpedia) {this.linkOnPodcastpedia = linkOnPodcastpedia;}public String getFeed() {return feed;}public void setFeed(String feed) {this.feed = feed;}public String getDescription() {return description;}public void setDescription(String description) {this.description = description;}}
2. 服务端代码
package com.base.pf.restful;import java.util.ArrayList;import java.util.List;import javax.ws.rs.GET;import javax.ws.rs.Path;import javax.ws.rs.PathParam;import javax.ws.rs.Produces;import javax.ws.rs.core.MediaType;import com.base.pf.restful.client.Podcast;@Path("/person")public class PersonResource {@GET@Produces(MediaType.TEXT_PLAIN)public String getPersons() {return "Hello person.";}@GET@Path("{id}")@Produces(MediaType.APPLICATION_XML)public List<Podcast> getPerson(@PathParam("id") Long id) {Podcast p = new Podcast();p.setId(id);p.setDescription("张三");p.setFeed("馒头");p.setLinkOnPodcastpedia("http://www.baidu.com");p.setTitle("正大光明");List<Podcast> list = new ArrayList<Podcast>();list.add(p);return list;}}
3. 客户端代码
package com.base.pf.restful.client;import java.util.List;import com.sun.jersey.api.client.Client;import com.sun.jersey.api.client.GenericType;import com.sun.jersey.api.client.WebResource;public class JerseyClient {public static void main(String[] args) {Client c = Client.create();WebResource resource = c.resource("http://localhost:8080/security/rest/person/1");// ClientResponse response = resource.get(ClientResponse.class);List<Podcast> list = resource.get(new GenericType<List<Podcast>>() {});for(Podcast p :list){System.out.print(p.getId());System.out.print("; "+p.getTitle());System.out.print("; "+p.getDescription());System.out.print("; "+p.getLinkOnPodcastpedia());System.out.println();}}}
0 0
- jersey 示例获取List<Object>(二)
- Jersey 示例(一)
- Jersey 入门(二)
- 获取 List<Object[]>,List<Object>,List<BreakType>中的两个变量
- map、list、map(Object,map)的前台获取遍历
- Jersey基础使用示例
- jersey client返回list
- SpringBoot 之 Jersey 集成示例代码(来自官网)
- 获取List<Map<String,Object>> list中的值得问题
- jersey学习之二(基于maven的例子)基于1.x的jersey
- jersey实现文件下载示例
- jersey服务端简单小示例
- SharePoint 2013 APP 安全示例 (二)获取用户信息
- tomcat发布基于jersey的WebService(二)
- REST+Jersey学习笔记(二)--根资源及注解
- Jersey架构下的Restful接口学习笔记(二)
- jersey中获取请求ip
- Java Jedis操作Redis示例(二)——list 生产者/消费者模式实现消息队列
- 分布式缓存系统Memcached简介与实践
- Struts2优点
- 211. Add and Search Word - Data structure design
- 项目中使用spring和redis的整合
- SpringMVC学习之helloworld(一)
- jersey 示例获取List<Object>(二)
- QCustomPlot实现矩形缩放图表
- 不使用广告而采集IDFA的app上架
- 顺序表的算法操作
- dom4j
- 【Zookeeper系列二】ZooKeeper典型应用场景实践
- 再谈Fragment(二)
- Andorid获取状态栏高度
- Ubuntu14.04主机重命名