From abc999d0c85e2257666093e24c423cad6ba75668 Mon Sep 17 00:00:00 2001 From: hulutech-web Date: Thu, 10 Oct 2024 10:58:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=9F=A5=E8=AF=A2sql?= =?UTF-8?q?=E6=B3=A8=E5=85=A5=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- paginator.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/paginator.go b/paginator.go index 82dfccb..cb10729 100644 --- a/paginator.go +++ b/paginator.go @@ -42,7 +42,9 @@ func (h *HttpResult) SearchByParams(params map[string]string, excepts ...string) if value == "" || key == "pageSize" || key == "total" || key == "currentPage" || key == "sort" || key == "order" { continue } else { - q = q.Where(key+" like ?", "%"+value+"%") + //q:=gorm.Expr(key+" like ?", "%"+value+"%") + //q = q.Where(key+" like ?", "%"+value+"%") + q = q.Raw(key+" like ?", "%"+value+"%").(orm.Query) } } return q @@ -50,7 +52,7 @@ func (h *HttpResult) SearchByParams(params map[string]string, excepts ...string) return h } -func (r *HttpResult) ResultPagination(dest any,withes ...string) (http.Response, error) { +func (r *HttpResult) ResultPagination(dest any, withes ...string) (http.Response, error) { request := r.Context.Request() pageSize := request.Query("pageSize", "10") pageSizeInt := cast.ToInt(pageSize) @@ -58,7 +60,7 @@ func (r *HttpResult) ResultPagination(dest any,withes ...string) (http.Response, currentPageInt := cast.ToInt(currentPage) total := int64(0) for _, with := range withes { - r.Query = r.Query.With(with) + r.Query = r.Query.With(with) } r.Query.Paginate(currentPageInt, pageSizeInt, dest, &total) @@ -70,9 +72,9 @@ func (r *HttpResult) ResultPagination(dest any,withes ...string) (http.Response, // Corrected links generation links := Links{ First: proto + request.Origin().Host + URL_PATH + "?pageSize=" + pageSize + "¤tPage=1", - Last: proto + request.Origin().Host + URL_PATH + "?pageSize="+ pageSize + "¤tPage=" + strconv.Itoa(int(total)/pageSizeInt), - Prev: proto + request.Origin().Host + URL_PATH + "?pageSize="+ pageSize + "¤tPage=" + strconv.Itoa(currentPageInt-1), - Next: proto + request.Origin().Host + URL_PATH + "?pageSize="+ pageSize + "¤tPage=" + strconv.Itoa(currentPageInt+1), + Last: proto + request.Origin().Host + URL_PATH + "?pageSize=" + pageSize + "¤tPage=" + strconv.Itoa(int(total)/pageSizeInt), + Prev: proto + request.Origin().Host + URL_PATH + "?pageSize=" + pageSize + "¤tPage=" + strconv.Itoa(currentPageInt-1), + Next: proto + request.Origin().Host + URL_PATH + "?pageSize=" + pageSize + "¤tPage=" + strconv.Itoa(currentPageInt+1), } // Corrected total page calculation