最近学习北大青鸟的 视频课程
但视频内容中缺少了一个方法 想请各位帮忙看看 多少补充一下 或者给个实现的思路
现有的页面如下 HouseAction
package com.pb.web.action;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.pb.base.action.BaseAction;
import com.pb.service.IHouseService;
import com.pb.service.impl.HouseServiceImpl;
import com.pb.util.Page;
public class HouseAction extends BaseAction {
/**
*
*/
private static final long serialVersionUID = 1L;
private IHouseService service = new HouseServiceImpl();
public String doSearch(){
Map<String,Object> params = new HashMap();
params.put("page", page);
Object[] o =service.findAll(params);
page = new Page();
//Object[0]当前页的数据列表List,Object[1]总页数 ,Object[2]总记录数.
page.setList((List<Object>)o[0]);
page.setTotalCount(Integer.parseInt(String.valueOf(o[2])));
return "success";
}
}
HouseServiceImpl页面
package com.pb.service.impl;
import java.util.Map;
import com.pb.base.dao.IBaseDao.IHouseDAO;
import com.pb.base.dao.IBaseDao.IHouseDAOimpl;
import com.pb.entity.House;
import com.pb.service.IHouseService;
import com.pb.util.Page;
public class HouseServiceImpl implements IHouseService{
private IHouseDAO dao = new IHouseDAOimpl();
public void delete(House house) {
}
public Object[] findAll(Map<String, Object> params) {
Page page = (Page)params.get("page");//page 是import com.pb.util.Page;的对象
if(null == page){
page = new Page();
}
String hql = "from House house where 1=1";
String hqlCount = "select count(*)" + hql;
return dao.findPageByHql(hql+"order by house.adddate desc",hqlCount,page.getIndex(),page.getSize());
}
}
Page页面
package com.pb.util;
import java.util.List;
public class Page {
private int size = 5 ;//每页显示的内容输入数量
private int index = 1; //当前页码号
private int totalPageCount = 1;//总页数
private int totalCount = 0; //内容总数
private int[] numbers; //显示页数集合
protected List<Object> list;//要显示页面的数据的集合
public int getStartRow(){
return (index - 1)* size;
}
public int getEndRow(){
return index * size;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public int getTotalPageCount() {
return totalPageCount;
}
public void setTotalPageCount(int totalPageCount) {
this.totalPageCount = totalPageCount;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
if(totalCount >= 0){
this.totalCount = totalCount;
setTotalPageCountByRs();
}
}
//分多少页 共有多少页
private void setTotalPageCountByRs()
{
if(this.size>0 && this.totalCount > 0 && this.totalCount%this.size==0){
this.totalPageCount = this.totalCount / this.size;
}else if(this.size > 0 && this.totalCount > 0 && this.totalCount % this.size>0){
this.totalPageCount = (this.totalCount/this.size)+1;
}else{
this.totalPageCount = 0;
}
setNumbers(totalPageCount);
}
//
public void setNumbers(int totalPageCount){
if(totalPageCount > 0){
int[] numbers= new int[totalPageCount > 10? 10 :totalPageCount];//显示页面最大的页码量就是10个;
int k = 0;
for (int i = 0 ;i<totalPageCount;i++){
if((i>=index-(numbers.length/2+1)||i>=totalPageCount-numbers.length)){
numbers[k] = i+1;
k++;
}else if(k>numbers.length){
break;
}
}
}
}
public int[] getNumbers() {
return numbers;
}
public void setNumbers(int[] numbers) {