บทความนี้อธิบายวิธีการดำเนินการสองวิธีของการเพจไฮเบอร์เนต แบ่งปันสำหรับการอ้างอิงของคุณดังนี้:
1. เกณฑ์การแบ่งหน้า
หน้าสาธารณะ getPage (int currentPage, หน้า int, เกณฑ์ ... CRTS) {เกณฑ์ c = session.createCriteria (house.class); list = null; สำหรับ (int i = 0; i <crts.length; i ++) {c.add (crts [i]); TotalRecord = Integer.ValueOf (C.Uniqueresult (). ToString ()); C.SetProjection (NULL); C.SetFirStResult ((pageSize)*(CurrentPage-1)); C.SetMaxResults page (); page.setCurrentPage (CurrentPage); page.setPagesize (pagesize); page.settotalrecord (TotalRecord); page.setList (รายการ); หน้าคืน;}2. HQL PAGINATION
หน้าสาธารณะ getPage (int currentPage, หน้า int, string hql, object ... args) {String counthql = "Select count (*)"+hql.substring (hql.indexof ("จาก"); เซสชัน = hibernateutil.getInstance () getSession () args.length; i ++) {query.setParameter (i, args [i]);} int totalRecord = integer.valueof (query.uniqueresult ()+""); สำหรับ (int i = 0; i <args.length; i ++) {query.setParameter (i, args [i]);} query.setFirStreSult (หน้า*(currentPage-1)); query.setMaxResults page (); page.setCurrentPage (CurrentPage); page.setPagesize (pagesize); page.settotalrecord (TotalRecord); page.setList (รายการ); หน้าคืน;}ฉันหวังว่าคำอธิบายในบทความนี้จะเป็นประโยชน์กับการเขียนโปรแกรม Java ของทุกคนตามกรอบการทำงานของไฮเบอร์เนต