简体   繁体   English

struts中的分页

[英]pagination in struts

I have a requirement where I have to fetch some records from the database and then I have to show 50 records per page on a JSP.我有一个要求,我必须从数据库中获取一些记录,然后我必须在 JSP 上每页显示 50 条记录。 The page will be having First, Previous, Next and Last buttons on the screen.该页面将在屏幕上显示 First、Previous、Next 和 Last 按钮。 Has anyone implemented similar functionality in struts or similar framework?有没有人在 struts 或类似的框架中实现过类似的功能? also i dont want to get all records at once.我也不想一次获得所有记录。 please guide me how to implement?请指导我如何实施?

Thanks in Advance提前致谢

I use the Displaytag library for this.为此,我使用Displaytag库。 It works great in combination with Struts and jsp and provides sorting and pagination.它与 Struts 和 jsp 结合使用效果很好,并提供排序和分页。

Use Strust2 criteria API to set max results使用 Strust2 标准 API 设置最大结果

List<Class_Name> records = new ArrayList<Class_Name>();
private static SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session s = sf.openSession();
Criteria cr = s.createCriteria(Class_Name.class);
cr.setMaxResults(50);


records = cr.list();
s.close();

Use Struts 2 Jq Grid plugin It is plugin designed for struts2 .. display tag is depreciated.使用Struts 2 Jq Grid 插件它是为 struts2 设计的插件。 display tag已折旧。 You can achieve by just the use struts2 jqgrid tags and there are lot of other features also there您可以通过使用struts2 jqgrid tags来实现,还有很多其他功能

maybe you can try some JQuery plugin that handles all client-side processing and take data from the server-side code.也许您可以尝试一些处理所有客户端处理并从服务器端代码获取数据的 JQuery 插件。 You migh try http://www.datatables.net/ because it handles pagination, filtering, ordering and has much more features.您可以尝试http://www.datatables.net/,因为它处理分页、过滤、排序并具有更多功能。 Here is explained how you can integrate DataTables with java servlet application http://www.codeproject.com/KB/java/JQuery-DataTables-Java.aspx .这里解释了如何将 DataTables 与 java servlet 应用程序http://www.codeproject.com/KB/java/JQuery-DataTables-Java.aspx集成。

1)in Action Class Calculate total number of pages in action(fetch it from it from database and calculate like totalPages=totalEntries/pageSize) 1)在动作类中计算动作的总页数(从数据库中获取它并计算像totalPages=totalEntries/pageSize)

2) send pageNumber from jsp(while user click on page no), send pageSize from jsp(if user has to specify pageSize) or from action to Business. 2)从jsp发送pageNumber(当用户点击页面编号时),从jsp发送pageSize(如果用户必须指定pageSize)或从action发送到Business。 String query = "select empid, ename from employee by joindate desc limit " + start + "," + pageSize; String query = "select empid, ename from employee by joindate desc limit " + start + "," + pageSize;

Calculate Start like int start = (pageNumber * pageSize - pageSize);计算 Start like int start = (pageNumber * pageSize - pageSize);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM