Skip to content

$Dto.listAndCount

$Dto.listAndCount用于标注带分页的返回结果。

参数

名称描述
classRef使用$Dto.get生成的DTO class

1. 创建DTO

在 VSCode 中,可以通过右键菜单Vona Create/Dto创建 DTO 的代码骨架:

typescript
@Dto()
export class DtoOrderSelectRes {}

2. 继承$Dto.listAndCount

diff
+ import { DtoOrderSelectResItem } from './orderSelectResItem.ts';

@Dto()
export class DtoOrderSelectRes
+ extends $Dto.listAndCount(DtoOrderSelectResItem) {}

DtoOrderSelectRes成员字段

名称说明
list当前页的条目列表
total数据总条数

标注API返回值

以 Controller Order 的 findMany 方法为例,标注 API 返回值:

diff
class ControllerOrder extends BeanBase {
  @Web.get('findMany')
+ @Api.body(DtoOrderSelectRes)
  async findMany(
    @Arg.filter(DtoOrderQueryPage) params: IQueryParams<ModelOrder>,
+ ): Promise<DtoOrderSelectRes> {
    return this.scope.model.order.selectAndCount(params);
  }
}
  • @Api.body:传入 DtoOrderSelectRes,用于标注 API 返回值

基于DtoOrderSelectRes生成的 Swagger/Openapi 效果如下:

基于 MIT 许可发布