みんなにページ分けの書き方を干してあげる

3375 ワード

すみません、頭を直してください.後で書きます.
PageSql page = new PageSql(sql.toString(), pageNo, pageSize);
public class PageSql {

	public int getPageNo()
	{
		return pageNo;
	}

	public int getPageSize()
	{
		return pageSize;
	}

	public String getSql(String keyFiled, String orderSQL) {
		String pageSql = "SELECT TOP " + pageSize + " * FROM (" + sql
				+ ") AS XX WHERE XX." + keyFiled + " NOT IN(SELECT TOP "
				+ pageSize * (pageNo - 1) + " " + keyFiled + " FROM (" + sql
				+ ") AS XX " + orderSQL + " ) " + orderSQL;
		return pageSql;
	}
}
Pagination p = this.extcutePageSql(page, page.getSqlServer("uid"," "));

public Pagination extcutePageSql(PageSql page, String pageSql) throws SQLException {
		int totalCount = getPageCount(page.getSql());
		Pagination p = new Pagination(page.getPageNo(), page.getPageSize(),
				totalCount);
		List list = executeQuery(pageSql);
		p.setList(list);
		return p;
	}

	private int getPageCount(String sql) {
		return getSession().createSQLQuery(sql).list().size();
	}
public class Pagination extends SimplePage implements java.io.Serializable,
		Paginable {

	public Pagination(int pageNo, int pageSize, int totalCount) {
		super(pageNo, pageSize, totalCount);
	}

	@SuppressWarnings("unchecked")
	private List list;

	@SuppressWarnings("unchecked")
	public List getList() {
		return list;
	}

	@SuppressWarnings("unchecked")
	public void setList(List list) {
		this.list = list;
	}

}
public class SimplePage implements Paginable {
	public SimplePage(int pageNo, int pageSize, int totalCount) {
		if (totalCount <= 0) {
			this.totalCount = 0;
		} else {
			this.totalCount = totalCount;
		}
		if (pageSize <= 0) {
			this.pageSize = DEF_COUNT;
		} else {
			this.pageSize = pageSize;
		}
		if (pageNo <= 0) {
			this.pageNo = 1;
		} else {
			this.pageNo = pageNo;
		}
		if ((this.pageNo - 1) * this.pageSize >= totalCount) {
			this.pageNo = totalCount / pageSize;
		}
	}
}
	public List executeQuery(String sql) throws SQLException {
		List resultList = new ArrayList();
		ResultSet resultSet = null;
		PreparedStatement ps = null;
		Connection con = null;
		try {
			con = this.getSession().connection();
			ps = con.prepareStatement(sql);
			resultSet = ps.executeQuery();
			Map map = null;
			for (; resultSet.next(); resultList.add(map)) {
				map = doCreateRow(resultSet);
			}
		} catch (SQLException sqle) {
			throw sqle;
		} catch (NullPointerException e) {
		} finally {
			try {
				if (resultSet != null) {
					resultSet.close();
				}
				if (ps != null) {
					ps.close();
				}
				if (con != null) {
					con.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return resultList;
	}

未完待機