當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeReferences類代碼示例

本文整理匯總了Java中org.springframework.hateoas.mvc.TypeReferences的典型用法代碼示例。如果您正苦於以下問題:Java TypeReferences類的具體用法?Java TypeReferences怎麽用?Java TypeReferences使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TypeReferences類屬於org.springframework.hateoas.mvc包,在下文中一共展示了TypeReferences類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: traversCustomersIT

import org.springframework.hateoas.mvc.TypeReferences; //導入依賴的package包/類
@Test
public void traversCustomersIT() {
    //Travers customers
    try {
        final Traverson traverson = new Traverson(new URI(BASE_URI), MediaTypes.HAL_JSON);
        final PagedResources<Resource<Customer>> resources = traverson
                .follow("customers")
                .toObject(new TypeReferences.PagedResourcesType<Resource<Customer>>() {
                });
        assertThat(resources.getContent()).isNotNull();
        assertThat(resources.getContent().size()).isEqualTo(3);
        System.err.println(resources.getContent());
    } catch (URISyntaxException e) {
        fail(e.getMessage());
    }
}
 
開發者ID:tuxdevelop,項目名稱:spring-data-repositories,代碼行數:17,代碼來源:CustomerRepositoryDataRestIT.java

示例2: traversCustomersResourceIT

import org.springframework.hateoas.mvc.TypeReferences; //導入依賴的package包/類
@Test
public void traversCustomersResourceIT() {
    //Travers customers
    try {
        final Traverson traverson = new Traverson(new URI(BASE_URI), MediaTypes.HAL_JSON);
        final PagedResources<Resource<Customer>> resources = traverson
                .follow("customers")
                .toObject(new TypeReferences.PagedResourcesType<Resource<Customer>>() {
                });
        assertThat(resources.getContent()).isNotNull();
        assertThat(resources.getContent().size()).isEqualTo(3);
        System.err.println(resources.getMetadata());
        for (Resource<Customer> resource : resources) {
            final List<Link> links = resource.getLinks();
            System.err.println(links);
            final Customer customer = resource.getContent();
            System.err.println(customer);
        }
    } catch (URISyntaxException e) {
        fail(e.getMessage());
    }
}
 
開發者ID:tuxdevelop,項目名稱:spring-data-repositories,代碼行數:23,代碼來源:CustomerRepositoryDataRestIT.java

示例3: traversCustomerFindByFirstNameIT

import org.springframework.hateoas.mvc.TypeReferences; //導入依賴的package包/類
@Test
public void traversCustomerFindByFirstNameIT() {
    //travers to findByFirstName
    try {
        final Map<String, Object> parameters = new HashMap<>();
        parameters.put("firstName", "Donnie");
        final Traverson traverson = new Traverson(new URI(BASE_URI), MediaTypes.HAL_JSON);
        final PagedResources<Resource<Customer>> resources = traverson
                .follow("customers", "search", "findByFirstName")
                .withTemplateParameters(parameters)
                .toObject(new TypeReferences.PagedResourcesType<Resource<Customer>>() {
                });
        assertThat(resources.getContent()).isNotNull();
        assertThat(resources.getContent().size()).isEqualTo(1);
        final List<Resource<Customer>> customers = new LinkedList<>(resources.getContent());
        final Customer customer = customers.get(0).getContent();
        assertThat(customer).isNotNull();
        assertThat(customer.getFirstName()).isEqualTo("Donnie");
    } catch (URISyntaxException e) {
        fail(e.getMessage());
    }

}
 
開發者ID:tuxdevelop,項目名稱:spring-data-repositories,代碼行數:24,代碼來源:CustomerRepositoryDataRestIT.java

示例4: getResource

import org.springframework.hateoas.mvc.TypeReferences; //導入依賴的package包/類
@Async
public <T> Future<Resource<T>> getResource(URI url, TypeReferences.ResourceType<T> type) throws
        InterruptedException, IOException {
    RequestEntity<Void> request = RequestEntity.get(url).accept(HAL_JSON).build();
    LOG.debug("Requesting: " + request.toString());
    Resource<T> body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody();
    LOG.debug("Received: " + body.toString());
    return new AsyncResult<>(body);
}
 
開發者ID:microservices-demo,項目名稱:orders,代碼行數:10,代碼來源:AsyncGetService.java

示例5: getDataList

import org.springframework.hateoas.mvc.TypeReferences; //導入依賴的package包/類
@Async
public <T> Future<Resources<T>> getDataList(URI url, TypeReferences.ResourcesType<T> type) throws
        InterruptedException, IOException {
    RequestEntity<Void> request = RequestEntity.get(url).accept(HAL_JSON).build();
    LOG.debug("Requesting: " + request.toString());
    Resources<T> body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody();
    LOG.debug("Received: " + body.toString());
    return new AsyncResult<>(body);
}
 
開發者ID:microservices-demo,項目名稱:orders,代碼行數:10,代碼來源:AsyncGetService.java

示例6: getRubricAssociationResource

import org.springframework.hateoas.mvc.TypeReferences; //導入依賴的package包/類
/**
 * Returns the ToolItemRubricAssociation resource for the given tool and associated item ID, wrapped as an Optional.
 * @param toolId the tool id, something like "sakai.assignment"
 * @param associatedToolItemId the id of the associated element within the tool
 * @return
 */
protected Optional<Resource<ToolItemRubricAssociation>> getRubricAssociationResource(String toolId, String associatedToolItemId) throws Exception {

    TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>> resourceParameterizedTypeReference =
            new TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>>() {};

    URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX);
    Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON);

    Traverson.TraversalBuilder builder = traverson.follow("rubric-associations", "search",
            "by-tool-item-ids");

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(toolId)));
    builder.withHeaders(headers);

    Map<String, Object> parameters = new HashMap<>();
    parameters.put("toolId", toolId);
    parameters.put("itemId", associatedToolItemId);

    Resources<Resource<ToolItemRubricAssociation>> associationResources = builder.withTemplateParameters(
            parameters).toObject(resourceParameterizedTypeReference);

    // Should only be one matching this search criterion
    if (associationResources.getContent().size() > 1) {
        throw new IllegalStateException(String.format(
                "Number of rubric association resources greater than one for request: %s",
                associationResources.getLink(Link.REL_SELF).toString()));
    }

    Optional<Resource<ToolItemRubricAssociation>> associationResource = associationResources.getContent().stream().findFirst();

    return associationResource;
}
 
開發者ID:sakaiproject,項目名稱:sakai,代碼行數:40,代碼來源:RubricsServiceImpl.java


注:本文中的org.springframework.hateoas.mvc.TypeReferences類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。