JdbcTemplate + SQL Server 2005 Paging +extjs

Source: Internet
Author: User

JdbcTemplate + SQL Server 2005 Paging +extjs
 PackageCom.ur.util;ImportJava.util.List;ImportJava.util.Map;ImportOrg.springframework.jdbc.core.JdbcTemplate; Public  class pagination {     Public Static Final intNumbers_per_page = -;Private intoffset =0;Private intLimit = -;Private intTotalSize;PrivateList<map<string, object>> resultlist;PrivateJdbcTemplate jtemplate; Public pagination() {    } Public pagination(String SQL,intOffsetintLimit,jdbctemplate jtemplate) {setoffset (offset);        Setlimit (limit); Setjtemplate (jtemplate);intOrderbyindex = Sql.tolowercase (). LastIndexOf ("ORDER BY");if(Orderbyindex <=0) {Throw NewUnsupportedoperationexception ("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)); } PublicStringgetlimitstring(String SQL,intOffsetintLimit) {returngetlimitstring (SQL, offset >0, Offset,limit); } PublicStringgetlimitstring(String SQL,BooleanHasoffset,intOffsetintLimit) {intOrderbyindex = Sql.tolowercase (). LastIndexOf ("ORDER BY");if(Orderbyindex <=0) {Throw NewUnsupportedoperationexception ("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);intInsertpoint = getsqlafterselectinsertpoint (sql); StringBuilder Sbsql =NewStringBuilder (Sql.length () + -). Append ("with Temppagination as ("). Append (Sqlremoveorderby). Insert (Insertpoint + at,"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) +"") ; }returnSbsql.tostring (); }Private Static int Getsqlafterselectinsertpoint(String SQL) {intSelectindex = Sql.tolowercase (). IndexOf ("SELECT");Final intSelectdistinctindex = Sql.tolowercase (). IndexOf ("SELECT distinct");returnSelectindex + (Selectdistinctindex = = Selectindex?) the:6); } Public int GetOffset() {returnOffset } Public void SetOffset(intOffset) { This. offset = offset; } Public int Getlimit() {returnLimit } Public void Setlimit(intLimit) { This. limit = limit; } Public int gettotalsize() {returnTotalSize; } Public void settotalsize(intTotalSize) { This. totalsize = TotalSize; } PublicList<map<string, object>>getresultlist() {returnResultlist; } Public void setresultlist(list<map<string, object>> resultlist) { This. resultlist = resultlist; } PublicJdbcTemplategetjtemplate() {returnJtemplate; } Public void setjtemplate(JdbcTemplate jtemplate) { This. jtemplate = jtemplate; }}

Business call pagination pagination = new pagination (sqlsb.tostring (), start,limit,this.jdbctemplate);

JdbcTemplate + SQL Server 2005 Paging +extjs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.