java - spring data rest + restTemplate cannot obtain the data collection when building a data reading and writing service
过去多啦不再A梦
过去多啦不再A梦 2017-06-12 09:27:10
0
1
693

Client:

ParameterizedTypeReference<PagedResources<Pass>> responseType =
                new ParameterizedTypeReference<PagedResources<Pass>>() {};
PagedResources<Pass> passes =restTemplate.exchange(uri, HttpMethod.GET, null, responseType).getBody();

Server:

@RepositoryRestResource(collectionResourceRel = "pass", path = "pass")
public interface PassRepository extends JpaRepository<Pass,String> {
    List<Pass> findByCarPlate(@Param("carPlate")String carPlate);
}

The data can be obtained normally by inputting URI on the web page, but the result is empty every time. Does anyone know how to solve it?

There is no problem in obtaining a single object, but there is a problem with the data set

过去多啦不再A梦
过去多啦不再A梦

reply all(1)
世界只因有你

Let me answer it myself, it’s still a problem with RestTemplate configuration.
Answer on stackoverflow

PagedResources does not have the _embedded attribute, resulting in the inability to obtain content.

objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

This configuration seems to eliminate the function of parsing failure if the fields do not match, similar to @JsonIgnoreProperties.

I don’t know if I understand it correctly. I hope someone who understands can explain it.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!