TypeOrm+Nest.js分页处理(含GROUP BY分组查询)

说明:该代码为已经过测试的生产环境代码
若有所帮助,望君轻轻一点,手有余香

import {
    RpcException } from '@nestjs/microservices';
import {
    EntityManager, getManager, SelectQueryBuilder } from 'typeorm';

/*
 * @Author: Horace
 * @Date: 2019-08-30 14:21:12
 * @Last Modified by: Horace
 * @Last Modified time: 2019-08-30 14:21:12
 */
export class Pagination {
   
  // @IsNotEmpty()
  // @ApiModelProperty({ description: "页码", type: "number", example: 1 })
  private pageNum: number;
  // @IsNotEmpty()
  // @ApiModelProperty({ description: "一页显示条数", type: "number", example: 10 })
  private pageSize: number;
  // @ApiModelProperty({ description: "总页数", type: "number", example: 10 })
  private totalNum: number;
  // @ApiModelProperty({ description: "总条数", type: "number", example: 10 })
  private totalRows: number;
  // @ApiModelProperty({ description: "数据" })
  public data?: any[];

  public get _pageNum(): number {
   
    return this.pageNum;
  }

  public set _pageNum(param: number) {
   
    if (param <= 0) {
   
      param = 1;
    }
    // if (param > this._totalNum) {
   
    //     param = this._totalNum;
    // }
    this.pageNum = param;
  }

  public get _pageSize() {
   
    return this.pageSize;
  }

  public set _pageSize(param: number) {
   
    this.pageSize = param;
  }

  public get _totalRows() {
   
    return this.totalRows;
  }

  public set _totalRows(param: number) {
   
    this.totalRows = param;
  }

  // @ApiModelProperty({ description: "总页数", type: "number", example: 10 })
  public get _totalNum

你可能感兴趣的:(typeorm,后端)