ssm实现分页

model层
private Integer currPage;
private int totalSize;
private int totalPage;

private int minnumber;

private int maxnumber;

private List<ArticleInfo>  data;

public int page_size=5;

public void initTotalPage(){
if(totalSize%page_size==0){

totalPage=totalSize/page_size;
}else{
totalPage =totalSize/page_size+1;
}
}
//需要注意的是最小值是当前页-1
public void setMinnumber((Integer  currPage) {
if(currPage==1){
minnumber =0;
}else{
minnumber=(currPage-1)*page_size;
}


}


public int getMaxnumber() {
return maxnumber;
}


public void setMaxnumber(Integer currPage) {
if(currPage==1){
maxnumber=page_size;
}else{
maxnumber =currPage*page_size;
}

}


mapper.xml


//分页的sql语句
<select id="sellArticle"  parameterType="com.blog.util.Show" resultType="ArticleInfo">
 select  id  ,Userno ,type,Title ,Content ,Personaltypeno,Categno,Time ,Brief  
 ,status from(select ROWNUM rd ,id  ,Userno ,type,Title ,Content ,Personaltypeno,Categno,Time,Brief  
 ,status  from articleinfo where  <![CDATA[ROWNUM<=#{maxnumber}]]>) where rd>#{minnumber}  

</select>


//求文章的数量
<select id="selArtCount"   resultType="int">
select count(*)  from articleinfo
</select>


mapper.java
public int selArtCount();
public List<ArticleInfo> sellArticle(Show show); 


service接口
public Show getAllPage(Integer currPage,ArticleInfo articleInfo);


service接口实现类
public Show getAllPage(Integer currPage, ArticleInfo articleInfo) {
Show page =new Show();
if(currPage==null) currPage=1;
page.setCurrPage(currPage);
int Count =articleInfoMapper.selArtCount(articleInfo);
page.setTotalSize(Count);
page.initTotalPage();
page.setMinnumber(currPage);
page.setMaxnumber(currPage);
page.setData(articleInfoMapper.sellArticle(page));
return page;
}


controller层实现
@RequestMapping(value="/showjsp")
public String showjsp(Model model,Integer currPage,ArticleInfo articleInfo ){

model.addAttribute("list", articleInfoService.getList());  
model.addAttribute("page",articleInfoService.getAllPage(currPage, articleInfo ));
return "index";
}


jsp中
<script type="text/javascript">
 
 function showdemo(){  
 var currPage='${page.currPage+1}';
 var totalPage='${page.totalPage}';
 if(currPage<=totalPage){
 window.location.href='ArticleController/showjsp?currPage='+currPage;
 }else{
  return false;
 }

}  ;
 function showsyy(){  
/* debugger; */
 var currPage='${page.currPage-1}';
/*   alert(currPage); */
 var totalPage='${page.totalPage}';
 if(currPage>0){
 window.location.href='ArticleController/showjsp?currPage='+currPage;
 }else{
  return false;
 }
}  ;
</script>
<c:forEach items="${page.data}" var="per">
    <h3>${per.title}</h3>
    <figure><img src="upload/{per.photo}"></figure>
    <ul>
      <p>${per.content}</p>
      <a  href="loginController/showuap" target="_blank" class="readmore">阅读全文>></a>
    </ul>
    <p class="dateview"><span><fmt:formatDate value="${per.time}" pattern="yyyy-MM-dd HH:mm:ss"/></span><span>作者编号:${per.userno}</span><span>文章类型:${per.type}</span></p>
   
  </c:forEach>
  <div><span><a href="ArticleController/showjsp?currPage=1">首页</a></span>
    <span><a href="javascript:;" οnclick="showsyy()" >上一页</a></span>
   
    <a href="javascript:;" id="showdemo"  οnclick="showdemo()">下一页</a> 
    <span><a href="#">第${page.currPage}页/共${page.totalPage}页</a></span>
    <span><a href="ArticleController/showjsp?currPage=${page.totalPage}">末页</a></span>
  </div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值