增加分页
This commit is contained in:
2
main.go
2
main.go
@@ -91,6 +91,8 @@ func registerRoutes(r *gin.Engine) {
|
|||||||
models.DB.Select("*").Offset(offset).Limit(pager.PageSize).Find(&items, "type = ?", "post")
|
models.DB.Select("*").Offset(offset).Limit(pager.PageSize).Find(&items, "type = ?", "post")
|
||||||
c.HTML(http.StatusOK, "index.tmpl", gin.H{
|
c.HTML(http.StatusOK, "index.tmpl", gin.H{
|
||||||
"Items": items,
|
"Items": items,
|
||||||
|
"Pager": pager,
|
||||||
|
"Title": "文章列表",
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
r.GET("/createcontent", func(c *gin.Context) {
|
r.GET("/createcontent", func(c *gin.Context) {
|
||||||
|
|||||||
@@ -1,18 +1,28 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>My Blog</title>
|
<title>{{ .Title}}</title>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
body{
|
body{
|
||||||
background: #f8f8f8;
|
background: #f8f8f8;
|
||||||
}
|
}
|
||||||
|
.layui-main {
|
||||||
|
width: 1140px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
.container {
|
.container {
|
||||||
width: 1170px;
|
width: 1170px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
.header .layui-nav {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
padding: 0;
|
||||||
|
background: none;
|
||||||
|
}
|
||||||
.post-list {
|
.post-list {
|
||||||
width: 75%;
|
width: 75%;
|
||||||
float: left;
|
float: left;
|
||||||
@@ -40,8 +50,18 @@
|
|||||||
|
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<div class="layui-main">
|
<div class="layui-main">
|
||||||
<h1>Welcome to my blog!<a class="logo" href="https://www.hanxiaonuan.cn/">韩小暖的博客</a></h1>
|
<h1><a class="logo" href="https://www.hanxiaonuan.cn/">韩小暖的博客</a></h1>
|
||||||
</div>
|
</div>
|
||||||
|
<ul class="layui-nav">
|
||||||
|
<li class="layui-nav-item layui-hide-xs layui-this">
|
||||||
|
<a href="https://www.hanxiaonuan.cn/">首页</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="layui-nav-item layui-hide-xs ">
|
||||||
|
<a href="https://www.hanxiaonuan.cn/start-page.html" title="关于">关于</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<span class="layui-nav-bar"></span></ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
@@ -58,6 +78,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
<div class="page-navigator">
|
||||||
|
共 {{ .Total }} 条,每页 {{ .PageSize }} 条,当前第 {{ .Page }} 页</div>
|
||||||
|
<div class="pagination">
|
||||||
|
{{ if .PrevPage }}
|
||||||
|
<a href="/page/{{ .PrevPage }}">上一页</a>
|
||||||
|
{{ end }}
|
||||||
|
{{ if .NextPage }}
|
||||||
|
<a href="/page/{{ .NextPage }}">下一页</a>
|
||||||
|
{{ end }}
|
||||||
|
<a href="/">首页</a>
|
||||||
|
<a href="/page/{{ .Total }}">尾页</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="sidebar">
|
<div class="sidebar">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
|
|||||||
Reference in New Issue
Block a user