1
从AbstractRepositoryRestController#entitiesToResources
源:返回一个空的“内容”数组当页面没有任何元素
if (page.getContent().isEmpty()) {
return pagedResourcesAssembler.toEmptyResource(page, domainType, baseLink);
}
当一个页面没有任何元素,春季数据REST是置于"content"
节点与无用信息的对象(在我的观点),如:
"content": [
{
"relTargetType" : "my.company.ClassName",
"collectionValue" : true,
"value" : [ ]
}
]
- 什么是提供信息的想法/目的是什么?
- 有什么办法可以返回空数组
"content": []
当page.getContent().isEmpty()
? - 如果不可能,客户应该如何处理这种意外的格式?
他们解析迭代它的content
,并将每个元素映射到某个域实体。由于它不是域实体,因此它们失败。获取第一个元素并检查它是否存在某些特定字段(例如relTargetType
)看起来很脏,是不是?
对不起,它是如何相关的问题? – Andrew
你问了如何返回空数组,而不是数组使用列表,并初始化为新列表并将其返回为空 –
当条件特定(页面没有元素)时,我在问如何通过Spring Data serialisers来做到这一点, – Andrew