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{