Java paging code implementation 1

Source: Internet
Author: User

Public class pagecut {
 
Private int sump; // the total number of pages.
Private int CURP; // current page number
Private int pagesize; // page size
Private collection result;
 
Public pagecut (){
Super ();
}

Public int getcurp (){
Return CURP;
}

Public void setcurp (int curp ){
This. CURP = CURP;
}

Public int getpagesize (){
Return pagesize;
}

Public void setpagesize (INT pagesize ){
This. pagesize = pagesize;
}
//*****************************
// The name parameter is the class name

Public Collection getresult (string name ){

Session session = hbnutil. getsession ();
Transaction TRAN = session. begintransaction ();
Tran. Begin ();
String hql = "from" + name;
List list = NULL;
Try {
List = session. createquery (hql ).
Setfirstresult (curp-1) * pagesize). setmaxresults (pagesize). List ();
} Catch (exception e ){
E. printstacktrace ();
Throw new daoexception ("Dao error in findpage" + name );
}
System. Out. println (list );

Return list;
}
//*****************************
Public void setresult (Collection result ){
This. Result = result;
}

Public int getsump (){
Return sump;
}
 
Public int initsump (string name ){

Session session = hbnutil. getsession ();
Transaction TRAN = session. begintransaction ();
Int sum = 0;
String hql = "select count (a) from" + name + "";
Sum = integer. parseint (session. createquery (hql). uniqueresult (). tostring ());
If (sum % pagesize = 0 ){
Sump = sum/pagesize;
} Else {
Sump = sum/pagesize + 1;
}
Tran. Commit ();
Session. Close ();
Return sum;
}
}

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.