233443
```
func (ProjectController) ReadList(ctx echo.Context) error {
limit := 20
curPage := goutils.MustInt(ctx.QueryParam("p"), 1)
paginator := logic.NewPaginator(curPage)
paginator.SetPerPage(limit)
total := logic.DefaultProject.Count(ctx, "")
pageHtml := paginator.SetTotal(total).GetPageHtml(ctx.Request().URL().Path())
pageInfo := template.HTML(pageHtml)
projects := logic.DefaultProject.FindAll(ctx, paginator, "id DESC", "status IN(?,?)", model.ProjectStatusNew, model.ProjectStatusOnline)
num := len(projects)
if num == 0 {
if curPage == int(total) {
return render(ctx, "projects/list.html", map[string]interface{}{"projects": projects, "activeProjects": "active"})
} else {
return ctx.Redirect(http.StatusSeeOther, "/projects")
}
}
// 获取当前用户喜欢对象信息
me, ok := ctx.Get("user").(*model.Me)
var likeFlags map[int]int
if ok {
likeFlags, _ = logic.DefaultLike.FindUserLikeObjects(ctx, me.Uid, model.TypeProject, projects[0].Id, projects[num-1].Id)
}
return render(ctx, "projects/list.html", map[string]interface{}{"projects": projects, "activeProjects": "active", "page": pageInfo, "likeflags": likeFlags})
}
```
有疑问加站长微信联系(非本文作者))