java - spring data rest + restTemplate 构建数据读写服务时无法获取数据集合
问题描述
客户端:
ParameterizedTypeReference<PagedResources<Pass>> responseType =new ParameterizedTypeReference<PagedResources<Pass>>() {};PagedResources<Pass> passes =restTemplate.exchange(uri, HttpMethod.GET, null, responseType).getBody();
服务端:
@RepositoryRestResource(collectionResourceRel = 'pass', path = 'pass')public interface PassRepository extends JpaRepository<Pass,String> { List<Pass> findByCarPlate(@Param('carPlate')String carPlate);}
网页输入uri能正常得到数据,但是用这种方式每次都是获取为空,请问有人知道怎么解决吗?
单个对象获取没问题,就是数据集有问题
问题解答
回答1:自己来解答吧,还是RestTemplate配置的问题。stackoverflow上的解答
PagedResources没有_embedded属性,导致无法获得content.
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
这段配置看样子是把字段不匹配就解析失败功能干掉了,类似@JsonIgnoreProperties.
不知道理解对不对。希望有懂的同学讲解一下。
相关文章:
1. android - weex 项目createInstanceReferenceError: Vue is not defined2. PHPExcel表格导入数据库怎么导入3. android - 哪位大神知道java后台的api接口的对象传到前端后输入日期报错,是什么情况?求大神指点4. javascript - 如图,百度首页,查看源代码为什么什么都没有?5. pdo 写入到数据库的内容为中文的时候写入乱码6. vue2.0+webpack 如何使用bootstrap?7. PHP类封装的插入数据,总是插入不成功,返回false;8. docker绑定了nginx端口 外部访问不到9. 请问PHPstudy中的数据库如何创建索引10. mac连接阿里云docker集群,已经卡了2天了,求问?
