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;
}
<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 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>
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
<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>