JdbcTemplate + sqlserver 2005 分页+Extjs
来源:互联网 发布:plc梯形图编程规则 编辑:程序博客网 时间:2024/05/19 00:12
JdbcTemplate + sqlserver 2005 分页+Extjs
package com.ur.util;import java.util.List;import java.util.Map;import org.springframework.jdbc.core.JdbcTemplate;public class Pagination { public static final int NUMBERS_PER_PAGE = 20; private int offset = 0; private int limit = 20; private int totalSize; private List<Map<String, Object>> resultList; private JdbcTemplate jTemplate; public Pagination() { } public Pagination(String sql, int offset, int limit,JdbcTemplate jTemplate){ setOffset(offset); setLimit(limit); setjTemplate(jTemplate); int orderByIndex = sql.toLowerCase().lastIndexOf("order by"); if (orderByIndex <= 0) { throw new UnsupportedOperationException( "must specify 'order by' statement to support limit operation with offset in sql server 2005"); } String totalSql = "select count(*) as totalsize from ("+sql.toLowerCase().substring(0, orderByIndex) +") totalTable "; setTotalSize(this.jTemplate.queryForInt(totalSql)); String sqls = this.getLimitString(sql, offset, limit); setResultList(this.jTemplate.queryForList(sqls)); } public String getLimitString(String sql, int offset, int limit) { return getLimitString(sql, offset > 0,offset,limit); } public String getLimitString(String sql, boolean hasOffset, int offset, int limit) { int orderByIndex = sql.toLowerCase().lastIndexOf("order by"); if (orderByIndex <= 0) { throw new UnsupportedOperationException( "must specify 'order by' statement to support limit operation with offset in sql server 2005"); } String sqlOrderBy = sql.substring(orderByIndex + 8); String sqlRemoveOrderBy = sql.substring(0, orderByIndex); int insertPoint = getSqlAfterSelectInsertPoint(sql); StringBuilder sbSql = new StringBuilder(sql.length() + 100).append("with tempPagination as(").append(sqlRemoveOrderBy).insert( insertPoint + 23, " ROW_NUMBER() OVER(ORDER BY " + sqlOrderBy + ") as RowNumber,").append( ") select * from tempPagination "); if(offset != -1 && limit !=-1){ sbSql.append(" where RowNumber between "+(offset+1)+" and "+(offset+limit)+"") ; } return sbSql.toString(); } private static int getSqlAfterSelectInsertPoint(String sql) { int selectIndex = sql.toLowerCase().indexOf("select"); final int selectDistinctIndex = sql.toLowerCase().indexOf("select distinct"); return selectIndex + (selectDistinctIndex == selectIndex ? 15 : 6); } public int getOffset() { return offset; } public void setOffset(int offset) { this.offset = offset; } public int getLimit() { return limit; } public void setLimit(int limit) { this.limit = limit; } public int getTotalSize() { return totalSize; } public void setTotalSize(int totalSize) { this.totalSize = totalSize; } public List<Map<String, Object>> getResultList() { return resultList; } public void setResultList(List<Map<String, Object>> resultList) { this.resultList = resultList; } public JdbcTemplate getjTemplate() { return jTemplate; } public void setjTemplate(JdbcTemplate jTemplate) { this.jTemplate = jTemplate; }}
业务调用 Pagination pagination = new Pagination(sqlSb.toString(),start,limit,this.jdbcTemplate);
0 0
- JdbcTemplate + sqlserver 2005 分页+Extjs
- sqlserver 2005 分页查询
- Spring JdbcTemplate 查询分页
- Spring JdbcTemplate 查询分页
- JDBCTemplate 分页查询
- 使用JdbcTemplate分页
- springMvc +Jdbctemplate+分页
- extjs分页
- extjs分页
- ExtJs分页
- ExtJs分页
- Extjs分页
- extjs分页
- MS SqlServer 2005 分页处理
- SQLserver分页
- sqlserver分页
- sqlserver分页
- SQLSERVER 分页
- 肯定就发给你送
- Linux面试题汇总答案
- 将博客搬至51CTO
- maven框架开发springmvc+spring+mybatis
- Apache的配置技巧
- JdbcTemplate + sqlserver 2005 分页+Extjs
- nginx配置tomcat与配置rewrite。
- 机器学习中的数学(5)-强大的矩阵奇异值分解(SVD)及其应用
- Android取消标题栏&强制设置横(竖)屏方法
- 动态数组的模板类/求指定个数的素数
- 黑马程序员----面象对象及封装
- android学习笔记(二)布局
- AlphaAnimation无效
- ethercat Mark一下,后续在写