[nodejs] nodejs开发个人博客六数据分页

控制器路由定义

首页路由:http://localhost:8888/

首页分页路由:http://localhost:8888/index/2

router= pageSize=( cid=).assignIndexData(cid,( currentPage=parseInt(req. cid=

分类列表分页路由:http://localhost:8888/category/分类id/分页

'/category/:cid/:page', cid= currentPage="article"

 模型数据部分

控制器调用article模型的assignIndexData()方法,参数:分类id,当前页,每页条数,响应对象

调用category模型的getAllList()方法得到分类list,参数:回调函数

调用article模型的getCount()方法得到总条数,参数:分类id,回调函数

调用article模型的getArticlePager()方法得到文章对象的数据list,参数:分类id,当前页,每页条数,回调函数

对上一页,下一页进行-1和+1,并进行判断,上一页应大于0,下一页应小于等于总页数(总条数/每页条数 向上取整)

把数据分配到模板上

= condition=""(categoryId!=0="where category_id="+ sql="select count(*) num from article "+(currentPage<=0||!currentPage) currentPage=1 start=(currentPage-1)* end= condition=""(categoryId!=0="where category_id="+ sql="select * from article "+condition+" order by time desc limit "+start+","+"select time from article order by time desc" categoryModel=F.model("category" articleModel= categoryModel.getAllList( articleModel.getCount(cid, articleModel.getArticlePager(cid,articleList){ nextPage=(currentPage+1)>=Math.ceil(nums[0].num/pageSize) ? Math.ceil(nums[0].num/pageSize) : currentPage+1 prePage=(currentPage-1)<=0 ? 1 : currentPage-1 articleModel.getArchives( newArticleTime=( i=0;i"y年m月" data===0 ? 1 </span><span style="color: #008000;"&gt;/*</span><span style="color: #008000;"&gt;渲染模板</span><span style="color: #008000;"&gt;*/</span><span style="color: #000000;"&gt; res.render(</span>"home/index"<span style="color: #000000;"&gt;,data); }); }); }); }); }

};

 模板部分

<上一页 <下一页

效果图:

相关文章

这篇文章主要介绍“基于nodejs的ssh2怎么实现自动化部署”的...
本文小编为大家详细介绍“nodejs怎么实现目录不存在自动创建...
这篇“如何把nodejs数据传到前端”文章的知识点大部分人都不...
本文小编为大家详细介绍“nodejs如何实现定时删除文件”,内...
这篇文章主要讲解了“nodejs安装模块卡住不动怎么解决”,文...
今天小编给大家分享一下如何检测nodejs有没有安装成功的相关...