当前位置: 首页 > news >正文

做门户网站经验怎么自己做游戏软件

做门户网站经验,怎么自己做游戏软件,正规的网站制作电话多少,王展简历Spring-hateoas为应用程序创建遵循HATEOAS原理的基于REST的服务提供了一种极好的方法。 我的目的不是要展示如何创建服务本身#xff0c;而是要展示如何将客户端写入服务。 我将要使用的示例服务是Josh Long#xff08; starbuxman #xff09;编写的“ the-spring-rest-s… Spring-hateoas为应用程序创建遵循HATEOAS原理的基于REST的服务提供了一种极好的方法。 我的目的不是要展示如何创建服务本身而是要展示如何将客户端写入服务。 我将要使用的示例服务是Josh Long starbuxman 编写的“ the-spring-rest-stack ”。 我要使用的特定子项目是这里的阴影。 如果使用“ mvn jetty”命令运行此子项目则可以在http// localhost8080 / users / 2中使用基于REST的端点列出用户的详细信息其中“ 2”是用户的ID并给出一个以下结构的结果 {links: [{rel: self,href: http://localhost:8080/users/2}, {rel: customers,href: http://localhost:8080/users/2/customers}, {rel: photo,href: http://localhost:8080/users/2/photo}],id: 2,firstName: Lois,profilePhotoMediaType: null,lastName: Lane,username: loislane,password: null,profilePhotoImported: false,enabled: true,signupDate: 1370201631000 } 为了获得该用户的特定客户端点位于http// localhost8080 / users / 2 / customers / 17它提供以下结构的输出 {links: [{rel: self,href: http://localhost:8080/users/2/customers/17}, {rel: user,href: http://localhost:8080/users/2}],id: 17,signupDate: 1372461079000,firstName: Scott,lastName: Andrews,databaseId: 17 } 现在对于这两种服务的使用者而言结果可以由Spring-hateoas项目中的一个称为Resource的Java类型表示并且是具有以下签名的泛型类 public class ResourceT extends ResourceSupport {protected Resource() {this.content null;}public Resource(T content, Link... links) {this(content, Arrays.asList(links));}... 因此以上两种服务的使用者将获得以下两种类型 ResourceUser user .... //call to the serviceResourceCustomer customer ... //call to the service 现在的问题是由于上面的“用户”和“客户”是参数化类型如果我要使用杰克逊作为json处理器绑定这些类型我将按照以下方式进行操作 ObjectMapper objectMapper new ObjectMapper(); ResourceCustomer customer objectMapper.readValue(customerAsJson, Resource.class); ResourceUser user objectMapper.readValue(userAsJson, Resource.class); 上面的方法不起作用原因是由于Java类型擦除导致参数化Resource的类型信息丢失Jackson不知道创建Resource User或Resource Customer的实例 解决方法是使用超类型令牌 这实质上是一种提供像杰克逊库类型的信息和我以前的博客上讲述它在这里 。 这样将json映射到适当的参数化类型的工作代码将如下所示 ObjectMapper objectMapper new ObjectMapper(); ResourceCustomer customer objectMapper.readValue(customerAsJson, new TypeReferenceResourceCustomer() {}); ResourceUser customer objectMapper.readValue(userAsJson, new TypeReferenceResourceUser() {}); Spring的基于Rest的服务的客户端抽象是RestTemplate 它可以使用称为HttpMessageConverter的抽象处理各种消息格式xmljsonatom等以处理每种消息格式的绑定细节。 Spring RestTemplate提供了自己的Super Type令牌实现能够按照Jackson的TypeReference的路线将不同的消息格式绑定到参数化类型这被称为ParameterizedTypeReference 。 ParameterizedTypeReference可用于通过以下方式将用户和客户的Rest响应完全绑定到Java类型 RestTemplate restTemplate new RestTemplate(); ResponseEntityResourceUser responseEntity restTemplate.exchange(http://localhost:8080/users/2, HttpMethod.GET, null, new ParameterizedTypeReferenceResourceUser() {}, Collections.emptyMap()); if (responseEntity.getStatusCode() HttpStatus.OK) {ResourceUser userResource responseEntity.getBody();User user userResource.getContent(); }RestTemplate restTemplate new RestTemplate(); ResponseEntityResourceCustomer responseEntity restTemplate.exchange(http://localhost:8080/users/2/customers/17, HttpMethod.GET, null, new ParameterizedTypeReferenceResourceCustomer() {}, Collections.emptyMap()); if (responseEntity.getStatusCode() HttpStatus.OK) {ResourceCustomer customerResource responseEntity.getBody();Customer customer customerResource.getContent(); } 总之ParameterizedTypeReference提供了一种处理参数化类型的巧妙方法并且在使用基于Spring Hateoas的REST服务时非常有用。 参考 all和其他博客中使用我们的JCG合作伙伴 Biju Kunjummen 提供的Spring RestTemplate和Super类型令牌使用Spring-hateoas Rest服务 。 翻译自: https://www.javacodegeeks.com/2014/01/consuming-spring-hateoas-rest-service-using-spring-resttemplate-and-super-type-tokens.html
http://wiki.neutronadmin.com/news/139339/

相关文章:

  • 下载浙江平安建设信息系统网站网站开发需要的编程软件有哪些
  • 衡水网站制作费用公司建网
  • 东莞网站建设关键词html网页设计作业代码
  • 海珠营销型网站建设公司财政局网站建设自查报告
  • 山东助企网站建设买域名去哪个网站好
  • 网站建设与管理专业好找工作吗frontpage网页制作软件下载
  • 网站建设的常用技术有哪些创意设计专业
  • 网站设计评价指标谷歌外贸网站建站
  • 用自己的身份做网站备案阿里云 xampp wordpress
  • 可以做mv的视频网站好建设网站
  • 做网站苏州wordpress连接mysql拒绝
  • 网站建设 百度贴吧医院网站主页面设计
  • 长春怎么注册网站平台wordpress安装界面默认英文
  • 做一个自己的免费网站吗网页版qq在线登录
  • 安徽省六安市建设局网站相城专业的网站建设
  • 单页网站模板做seo做网站提供服务器吗
  • 做刷题网站赚钱么wordpress 4.1分页
  • 珠海营销型网站重庆网站建设推广
  • 网站的ftp地址是什么如何让自己做的网页有网站
  • 开发板厦门百度关键词优化
  • 图片展示型网站制作图片用什么软件
  • 电脑自带做网站的软件网站 移动app开发
  • 国外的模板网站有哪些信誉好的购物网站建设
  • 哪个网站可以做练习题网站建设吉金手指排名14
  • 包头市住房与城乡建设部网站百度推广弄个网站头像要钱吗?
  • 嘉兴企业网站网络营销软文范例大全800
  • 燕赵邯郸网站建设重庆传媒公司
  • 创意网站展示广东省有多少个市
  • 给个网站谢谢刷关键词排名软件有用吗
  • 快速搭建网站的好处银川网站建设推广