52 lines
921 B
Go
52 lines
921 B
Go
package controllers
|
|
|
|
import "liteblog/models"
|
|
|
|
type IndexController struct {
|
|
BaseController
|
|
}
|
|
|
|
//首页
|
|
// @router / [get]
|
|
func (c *IndexController) Get() {
|
|
limit := 10
|
|
|
|
page, err := c.GetInt("page", 1)
|
|
if err != nil && page <= 0 {
|
|
page = 1
|
|
}
|
|
|
|
title := c.GetString("title")
|
|
notes, err := models.QueryNoteByPage(title, page, limit)
|
|
if err != nil {
|
|
c.Abort500(err)
|
|
}
|
|
|
|
c.Data["notes"] = notes
|
|
// 得到文章的总数
|
|
count, err := models.QueryNoteCount(title)
|
|
if err != nil {
|
|
c.Abort500(err)
|
|
}
|
|
// 计算总页数
|
|
totalPage := count / limit
|
|
if count % limit != 0 {
|
|
totalPage += 1
|
|
}
|
|
|
|
c.Data["totalPage"] = totalPage
|
|
c.Data["page"] = page
|
|
c.Data["title"] = title
|
|
|
|
c.TplName = "index.html"
|
|
}
|
|
//留言
|
|
// @router /message [get]
|
|
func (c *IndexController) GetMessage() {
|
|
c.TplName = "message.html"
|
|
}
|
|
//关于
|
|
// @router /about [get]
|
|
func (c *IndexController) GetAbout() {
|
|
c.TplName = "about.html"
|
|
} |