pagination

package
v0.0.1-202203021618 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2022 License: MPL-2.0 Imports: 3 Imported by: 2

Documentation

Index

Constants

View Source
const DefaultPageSize = 10

Variables

This section is empty.

Functions

func CalculatePages

func CalculatePages(total, pageSize int64) [][]int64

CalculatePages 计算页面,获取带有起始值的页面的数组 @return 返回一个二维数组, 第一维是多少页,第二维是每页[]int64{start, end} e,g: 假设11个数的列表,分页pageSize是5,那么返回的是:

[]int64{
   []int64{0, 5},
   []int64{5, 10},
   []int64{10, 11},
}

Types

type Pagination

type Pagination struct {
	// contains filtered or unexported fields
}

func New

func New(page, pageSize int64, args ...int64) *Pagination

New pagination args[0] is default page size

func (*Pagination) GenLimitClause

func (p *Pagination) GenLimitClause() string

GenLimitClause 生成limit sql子句

func (*Pagination) GetSQLClause

func (p *Pagination) GetSQLClause(total int64) string

GetSQLClause 获取翻页SQL查询语句

1. 假如前端没有传过来last_pk, 那么返回值是 last_pk, LIMIT子句(LIMIT offset, pageSize) e,g: 0, "LIMIT 20, 10" => 在数据库查询时可能会被组装成 WHERE pk > 0 ... LIMIT 20, 10

2. 假如前端传过来了last_pk, 那么返回值是 last_pk, LIMIT子句(LIMIT pageSize) e,g: 123,"LIMIT 10" => 在数据库查询时可能会被组装成 WHERE pk > 123 ... LIMIT 10

func (*Pagination) Paging

func (p *Pagination) Paging(data interface{}) (int64, []interface{})

Paging 分页 @return total @return []interface{} 分页后的数据

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL