org.springframework.hateoas.Resource.getLink()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(4.3k)|赞(0)|评价(0)|浏览(72)

本文整理了Java中org.springframework.hateoas.Resource.getLink方法的一些代码示例,展示了Resource.getLink的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resource.getLink方法的具体详情如下:
包路径:org.springframework.hateoas.Resource
类名称:Resource
方法名:getLink

Resource.getLink介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-data-rest

protected Link resourceLink(RootResourceInformation resourceLink, Resource resource) {
  ResourceMetadata repoMapping = resourceLink.getResourceMetadata();
  Link selfLink = resource.getLink("self");
  String rel = repoMapping.getItemResourceRel();
  return new Link(selfLink.getHref(), rel);
}

代码示例来源:origin: joshlong/the-spring-rest-stack

@RequestMapping(method = POST)
HttpEntity<Void> writeUserProfilePhoto(@PathVariable Long user, @RequestParam MultipartFile file) throws Throwable {
  byte bytesForProfilePhoto[] = FileCopyUtils.copyToByteArray(file.getInputStream());
  this.crmService.writeUserProfilePhoto(user, MediaType.parseMediaType(file.getContentType()), bytesForProfilePhoto);
  Resource<User> userResource = this.userResourceAssembler.toResource(crmService.findById(user));
  List<Link> linkCollection = userResource.getLinks();
  Links wrapperOfLinks = new Links(linkCollection);
  HttpHeaders httpHeaders = new HttpHeaders();
  httpHeaders.add("Link", wrapperOfLinks.toString());  // we can't encode the links in the body of the response, so we put them in the "Links:" header.
  httpHeaders.setLocation(URI.create(userResource.getLink("photo").getHref())); // "Location: /users/{userId}/photo"
  return new ResponseEntity<>(httpHeaders, HttpStatus.ACCEPTED);
}

代码示例来源:origin: joshlong/the-spring-rest-stack

@RequestMapping(method = POST)
HttpEntity<Void> writeUserProfilePhoto(@PathVariable Long user, @RequestParam MultipartFile file) throws Throwable {
  byte bytesForProfilePhoto[] = FileCopyUtils.copyToByteArray(file.getInputStream());
  this.crmService.writeUserProfilePhoto(user, MediaType.parseMediaType(file.getContentType()), bytesForProfilePhoto);
  Resource<User> userResource = this.userResourceAssembler.toResource(crmService.findById(user));
  List<Link> linkCollection = userResource.getLinks();
  Links wrapperOfLinks = new Links(linkCollection);
  HttpHeaders httpHeaders = new HttpHeaders();
  httpHeaders.add("Link", wrapperOfLinks.toString());  // we can't encode the links in the body of the response, so we put them in the "Links:" header.
  httpHeaders.setLocation(URI.create(userResource.getLink("photo").getHref())); // "Location: /users/{userId}/photo"
  return new ResponseEntity<>(httpHeaders, HttpStatus.ACCEPTED);
}

代码示例来源:origin: spring-projects/spring-data-rest

Link l = new Link(entry.getValue().getLink("self").getHref(), entry.getKey().toString());
links.add(l);

代码示例来源:origin: BlackPepperSoftware/bowman

@Override
  public Object invoke(Object self, Method method, Method proceed, Object[] args) {
    Link selfLink = resource.getLink(Link.REL_SELF);
    return selfLink == null ? null : URI.create(selfLink.getHref());
  }
}

代码示例来源:origin: uk.co.blackpepper.bowman/bowman-client

@Override
  public Object invoke(Object self, Method method, Method proceed, Object[] args) {
    Link selfLink = resource.getLink(Link.REL_SELF);
    return selfLink == null ? null : URI.create(selfLink.getHref());
  }
}

代码示例来源:origin: BlackPepperSoftware/bowman

URI resolveForMethod(Method method, Object[] args) {
  String linkName = getLinkName(method);
  Link link = resource.getLink(linkName);
  
  if (link == null) {
    throw new ClientProxyException(String.format("Link '%s' could not be found!", linkName));
  }
  
  return URI.create(link.expand(args).getHref());
}

代码示例来源:origin: uk.co.blackpepper.bowman/bowman-client

URI resolveForMethod(Method method, Object[] args) {
  String linkName = getLinkName(method);
  Link link = resource.getLink(linkName);
  
  if (link == null) {
    throw new ClientProxyException(String.format("Link '%s' could not be found!", linkName));
  }
  
  return URI.create(link.expand(args).getHref());
}

代码示例来源:origin: org.springframework.data/spring-data-rest-webmvc

protected Link resourceLink(RootResourceInformation resourceLink, Resource resource) {
  ResourceMetadata repoMapping = resourceLink.getResourceMetadata();
  Link selfLink = resource.getLink("self");
  String rel = repoMapping.getItemResourceRel();
  return new Link(selfLink.getHref(), rel);
}

代码示例来源:origin: org.springframework.data/spring-data-rest-webmvc

Link l = new Link(entry.getValue().getLink("self").getHref(), entry.getKey().toString());
links.add(l);

相关文章

微信公众号

最新文章

更多