From d6ec44d4ef73bcf218a73628a0797e96130661c3 Mon Sep 17 00:00:00 2001 From: a7458969 <290198252@qq.com> Date: Sun, 1 Mar 2020 22:33:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E7=AB=A0=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=9F=A5=E6=89=BE=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/blog.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/controller/blog.go b/controller/blog.go index d6698dc..cde8d1e 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -27,6 +27,7 @@ func GetPageParaFromQuery(c *gin.Context) (int,int){ func GetArticles(c *gin.Context) { type ReqArticles struct { Name string `json:"name"` + Type int32 `json:"types"` } var req ReqArticles rsp := RespBase{"ERR",-1,nil} @@ -42,13 +43,23 @@ func GetArticles(c *gin.Context) { limit,offset := GetPageParaFromQuery(c) var sql string if req.Name != ""{ - sql = fmt.Sprintf("select * from doc where doc.name like '%%%s%%' limit %d offset %d",req.Name,limit,offset*limit) + if req.Type == 110{ + sql = fmt.Sprintf("select * from doc where doc.title like '%%%s%%' limit %d offset %d ",req.Name,limit,offset*limit) + }else{ + sql = fmt.Sprintf("select * from doc where doc.title like '%%%s%%' and doc.type = %d limit %d offset %d ",req.Name,req.Type,limit,offset*limit) + } }else{ - sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title,doc.type from doc limit %d offset %d",limit,offset) + if req.Type == 110{ + sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title from doc " + + "limit %d offset %d",limit,offset) + }else{ + sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title,doc.type from doc where doc.type = %d " + + "limit %d offset %d",req.Type,limit,offset) + } } e = db.GetMysqlClient().Query2(sql,&article) if nil != e{ - logs.Error(e.Error()) + logs.Error(e.Error(),sql) return } for k,_ := range article{