[color=red]高手请看这里:http://blog.youkuaiyun.com/YUHEN78/article/details/5910317
[/color]
我的分页代码:
从前台传来的值:
[color=red]final String type(查询条件), final int recordsInOnePage(一页的数量), final int recordsCount(第几页)
[/color]
DAO代码:
public List<Goods> getGoodsList(final String type, final int recordsInOnePage, final int recordsCount) {
final List<Goods> result = new Vector<Goods>();
final int[] types = new int[]{Types.INTEGER, Types.VARCHAR};[color=red](参数类型)[/color]
PreparedStatementCreatorFactory psc = new PreparedStatementCreatorFactory("select top(?)* from Goods where GoodsType=? Order by goodsID", types);
psc.setResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE);
psc.setUpdatableResults(false);
PreparedStatementCreator ps = psc.newPreparedStatementCreator(new Object[]{recordsCount * recordsInOnePage, type});[color=red](添加参数)[/color]
return this.jdbcTemplate.execute(ps, new PreparedStatementCallback<List>() {
@Override
public List doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
int start = (recordsCount - 1) * recordsInOnePage;[color=red](开始位置)[/color]
int end = start + recordsInOnePage;[color=red](结束位置)[/color]
ps.setMaxRows(end ); [color=red](处理的数据量,控制输出记录最大数量)[/color]
ResultSet rs = ps.executeQuery();
rs.first();[color=red](移动游标到第一行)[/color]
rs.relative(start - 1);[color=red](移动游标到开始行集的位置)[/color]
while (rs.next()) {[color=red](处理得到的数据)[/color]
Goods goods = new Goods(rs.getString("goodsID"), rs.getString("goodsName"), rs.getDouble("goodsPrice"), rs.getInt("goodsQuantity"), rs.getString("goodsType"), rs.getString("goodsPicture"), rs.getString("goodsDescription"));
result.add(goods);
System.out.println(goods.getGoodsID());
}
return result;
}
});
}
[/color]
我的分页代码:
从前台传来的值:
[color=red]final String type(查询条件), final int recordsInOnePage(一页的数量), final int recordsCount(第几页)
[/color]
DAO代码:
public List<Goods> getGoodsList(final String type, final int recordsInOnePage, final int recordsCount) {
final List<Goods> result = new Vector<Goods>();
final int[] types = new int[]{Types.INTEGER, Types.VARCHAR};[color=red](参数类型)[/color]
PreparedStatementCreatorFactory psc = new PreparedStatementCreatorFactory("select top(?)* from Goods where GoodsType=? Order by goodsID", types);
psc.setResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE);
psc.setUpdatableResults(false);
PreparedStatementCreator ps = psc.newPreparedStatementCreator(new Object[]{recordsCount * recordsInOnePage, type});[color=red](添加参数)[/color]
return this.jdbcTemplate.execute(ps, new PreparedStatementCallback<List>() {
@Override
public List doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
int start = (recordsCount - 1) * recordsInOnePage;[color=red](开始位置)[/color]
int end = start + recordsInOnePage;[color=red](结束位置)[/color]
ps.setMaxRows(end ); [color=red](处理的数据量,控制输出记录最大数量)[/color]
ResultSet rs = ps.executeQuery();
rs.first();[color=red](移动游标到第一行)[/color]
rs.relative(start - 1);[color=red](移动游标到开始行集的位置)[/color]
while (rs.next()) {[color=red](处理得到的数据)[/color]
Goods goods = new Goods(rs.getString("goodsID"), rs.getString("goodsName"), rs.getDouble("goodsPrice"), rs.getInt("goodsQuantity"), rs.getString("goodsType"), rs.getString("goodsPicture"), rs.getString("goodsDescription"));
result.add(goods);
System.out.println(goods.getGoodsID());
}
return result;
}
});
}