fix: pagination bug.
This commit is contained in:
@@ -8,7 +8,7 @@ require (
|
||||
github.com/go-kratos/kratos/v2 v2.7.1
|
||||
github.com/google/uuid v1.4.0
|
||||
github.com/stretchr/testify v1.8.4
|
||||
github.com/tx7do/go-utils v1.1.0
|
||||
github.com/tx7do/go-utils v1.1.3
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@@ -17,6 +17,13 @@ func BuildPaginationSelector(page, pageSize int32, noPaging bool) func(*sql.Sele
|
||||
}
|
||||
|
||||
func BuildPaginationSelect(s *sql.Selector, page, pageSize int32) {
|
||||
if page < 1 {
|
||||
page = paging.DefaultPage
|
||||
}
|
||||
|
||||
if pageSize < 1 {
|
||||
pageSize = paging.DefaultPageSize
|
||||
}
|
||||
offset := paging.GetPageOffset(page, pageSize)
|
||||
s.Offset(offset).Limit(int(pageSize))
|
||||
}
|
||||
|
||||
@@ -7,13 +7,5 @@ const (
|
||||
|
||||
// GetPageOffset 计算偏移量
|
||||
func GetPageOffset(pageNum, pageSize int32) int {
|
||||
if pageNum < 1 {
|
||||
pageNum = DefaultPage
|
||||
}
|
||||
|
||||
if pageSize < 1 {
|
||||
pageSize = DefaultPageSize
|
||||
}
|
||||
|
||||
return int((pageNum - 1) * pageSize)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user