ListResultDto 和 List 之间的区别

Difference between ListResultDto and List

在我的应用程序服务中,为什么我应该 return ListResultDto 而不是 returning List

这似乎是额外的工作。

在前端,这意味着我需要访问 items 属性 而不是将结果视为数组,例如

使用ListResultDto

.subscribe((next) => this.entities = next.items);

使用List

.subscrube((next) => this.entities = next);

使用 ListResultDto 可以让您在以后添加关于您的 items 的额外信息,而不会破坏您现有的 API。如果你 return items 作为一个数组,你就是在限制你的 API.

一个例子是PagedResultDto中的TotalCount,如果你想实现items的分页。