当前位置:Gxlcms > mysql > jdbcsqlserver分页

jdbcsqlserver分页

时间:2021-07-01 10:21:17 帮助过:74人阅读

(1). top ... not in , (2). top .... id( max ),(3).游标 这种方法感觉比上面三种要快 ,分享一下跟好的意见 使用的是org.springframework.jdbc.core. JdbcTemplate limit = 25; public ListMapString, Object findAll(String type, final int start, f

(1). top ... not in , (2). top .... id>(max),(3).游标

这种方法感觉比上面三种要快 ,分享一下跟好的意见

使用的是 org.springframework.jdbc.core.JdbcTemplate


limit = 25;
public List> findAll(String type, final int start, final int limit) {
StringBuilder builder = new StringBuilder();
List params = new ArrayList();//给占位符赋值
builder.append("select top " + (start + limit)//第一页,start=0 ()select top 25 * ,第二页 start=25 (select top 50 *)
+ " * from v_fulldata a where 1=1");
if (type != null && type != " ") {
builder.append(" and a.atype = ? ");
params.add(type);
}
builder.append(" order by wg13 desc;");

String sql = builder.toString();
List> list = (List>) getJdbc()
.query(sql, params.toArray(), new ResultSetExtractor() {
@Override
public Object extractData(ResultSet rs)
throws SQLException, DataAccessException {
List> list = new ArrayList>();
while (rs.next()) { //将查询结果循环
if (rs.getRow() < start) { //排除小于开始索引的数据
continue;
}
Map row = new HashMap();
ResultSetMetaData rsmd = rs.getMetaData();
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
row.put(rsmd.getColumnName(i), rs.getString(i));
}
list.add(row);
}
return list;
}
});
return list;
}

人气教程排行