In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains the "detailed introduction of Hibernate paging technology under JSP". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the detailed introduction of Hibernate paging technology under JSP".
This is the least code and the most concise Hibernate paging technology I know. I am lazy, so I try my best to reduce the amount of code, hehe. In the following language that people can understand, there are no more than two paging techniques for Hibernate:
1. Get the record from the database and divide it in memory. But when the number of records is very large, efficiency is very problematic.
two。 Use Hibernate physical pagination, only one page at a time. What pages and how many records per page are transmitted from the client, we should first query the total number of records that match the records, and then according to the total number of records and the current page, the number of records per page can be calculated how many records to take in the database. But two queries are inevitable.
So summed up the advantages and disadvantages of the two methods, if the amount of data is not very large (more than one million), use * method, otherwise you can choose the second one.
Because the amount of information in the database I want to operate does not meet the large standard, I have adopted a * method, which is described in more detail below.
First, take a look at one of my action:
Public ActionForward queryZcDoc (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {IZcDocService zcDocService= (IZcDocService) Application.getInstance (). GetBean ("zcDocServiceProxy"); List docList=zcDocService.queryZcDoc (); request.setAttribute ("doc", subMessList); return mapping.findForward ("queryDoc");}
The very simple code is to query the data, throw it into a List, then setAttribute, and then display it on the jsp page.
Let's talk about paging. For simplicity and versatility, I encapsulated the paging code into a single class. Let's take a look at this class:
Public class Fenye {public List fenye (ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {List list= (ArrayList) request.getAttribute ("list"); / *
There are some people here who may not understand, why take these parameters? Because my action method above is the one before paging, I can't see it.
Here is a post on the action method after paging:
Public ActionForward queryZcDoc (ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {IZcDocService zcDocService= (IZcDocService) Application.getInstance (). GetBean ("zcDocServiceProxy"); List docList=zcDocService.queryZcDoc (); request.setAttribute ("list", docList); List subMessList=new Fenye (). Fenye (mapping, form, request, response); request.setAttribute ("doc", subMessList); return mapping.findForward ("queryDoc");}
Compared with the above, there are actually two more lines of code to use the called method to keep the page concise, and then return the required data.
Then move on to the following:
* / List subMessList=null; / / what is saved at that time is the number of records to be displayed after using the paging technique int showCount = 5; / / the number of records displayed per page. Int showPage = 1; / / the number of pages currently displayed. Int size = list.size (); / / the total number of pieces of data obtained. Int pageCount = (size-1) / showCount + 1; / / the total number of pages to be displayed if (size
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.