如何在 Struts 2 中实现分页

How to implement a pagination in Struts 2(如何在 Struts 2 中实现分页)

本文介绍了如何在 Struts 2 中实现分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Struts 2 中为客户端显示和 Hibernate 作为持久层实现分页.

How can I implement paging in Struts 2 for the client side display and Hibernate as the persistence layer.

这是我到目前为止所做的代码:

Here is the code that I have done so far:

<display:table id="students" name="students" pagesize="2"
    export="false" requestURI="/student">
    <display:column property="studentRoll" title="Roll"
        paramId="studentRoll" sortable="true" />
    <display:column property="studentName" title="Name" sortable="true" />
    <display:column property="studentCourse" title="Course"
        sortable="true" />
    <display:setProperty name="paging.banner.placement" value="bottom" />
</display:table>

有没有什么方法可以在没有display标签的情况下实现这个?

Is there any way to implement this without display tag?

推荐答案

有办法实现它,我会给你一些建议.可能不是您正在寻找,而是使用显示标签,我真的怀疑您是否可以实现一些不想说那个词的东西.显示标签是一个库,用于简化 Web 上表格数据的表示,并且已经足够老,可以将它与现代技术(如 Ajax)和基于组件的脚本库(如 jQuery 等)一起使用.即使我已经看到显示标签 ajaxified 但我看到这只不过是增加了有问题的架构的复杂性.需要在此处添加基于属性的显示标签库的性质.创建它的目的是为了简化当时的使用或开发过程.如今,人们不再局限于定制和丑陋的解决方案.

There's a way to implement it and I will give you some recommendations. May be it's not that you are looking for but with the display tag I'm really doubt that you can implement something don't care to say that word. The display tag is a library created to simplify representation of tabular data on the web and already old enough to use it with the modern technologies like Ajax and component based scripting libraries like jQuery, etc. Even I've seen the display tag ajaxified but I see this is nothing more just adding the complexity to the problematic architecture. Needed to add here the nature of the display tag library it is property based. And it was created with the purpose to simplify usage or the development process that time. Nowadays people doesn't limit themselves with the custom and ugly solutions.

现在看看代码,如果我可以说这是一个代码,标签代表带有行和列的表格,可以使用标签、标题、其他 HTML 属性,甚至使用 CSS 来自定义它们,但这不是这个问题.

Now looking at the code if I can say that is a code, the tag represents the table with rows and columns given the possibility to customize them with labels, headers, other HTML attributes, even with CSS but this is out of this question.

属性名代表一个变量,其数据结构代表一个表格数据.它可能是一个列表列表或一组对象无关紧要.它可以是可迭代的并且有行和列是怎么回事.

The attribute name represent a variable with the data structure representing a tabular data. It could be a list of lists or a set of objects doesn't matter. What's the matter it could be iterable and have rows and columns.

属性pagesize指向每页的记录数.

The attribute pagesize points to the number of records per page.

给定的 URI 甚至不记得从服务器提供数据的内容是什么,或者只是为了转义.

The given URI even doesn't remember what it is to feed the data from the server or just for escape.

标签末尾附近是横幅位置,由属性设置.因此,您甚至不必使用它来实现任何代码,只需设置自定义属性即可.

And near the end of the tag is the banner placement, set with the property. So you even doesn't have to implement any code with it just setting properties for customization.

现在,用 Struts2 中的数据表示表格,有一个

Now, to represent the table with data in Struts2 there's an

<s:iterator var="row" begin="0" value="#request.navigator.list">

tag,列表是 students 或者别的什么都无所谓.导航器是类似于显示标签中的横幅的对象,但这里不是组件.带有按钮的组件导航器我将在后面介绍.

tag, the list is students or something else doesn't matter. The navigator is the object similar to the banner in display tag, but not a component here. The component navigator with the buttons I will describe later.

在迭代器中,您可以有任何表示行的内容.但这是不可能的.

Inside the iterator you may have any content representing the row. But this out of the question.

作为组件的导航器可以有不同的方式,例如

The navigator as the component could be given different ways simply for example

<s:property value="#request.navigator.bar" escapeHtml="false"/>  

然后列表中的数据是通过 SQL 或 HQL 或 Criteria API 无关紧要的从数据库中获取的.这分两步完成.首先检查希望返回的记录总数.它提供了在最后移动并且不超过页面大小的可能性.然后返回在页面上表示所需的有限行数.这些都在显示表格的操作中完成.该操作需要两个参数,第一行和页面大小.如果记录总数发生变化,这也需要更正导航器.

Then the data in the list are fetched from the database via SQL or HQL or Criteria API doesn't matter. This is done in two steps. First checked the total number of records wishing to return. It gives the possibility to move at the end and not exceed the pagesize. Then return limited number of rows needed to represent on the page. These all done in the action that displays the table. The action to work needs two parameters the first row and pagesize. This is also needed to correct the navigator if the total number of records changed.

这就是我想回答的关于如何实现页面导航逻辑的问题.我尽量不要写很多很多代码,因为它毫无疑问.

That's what I wanted to answer about how to implement the page navigation logic. I tried to not to write many, many code as for it out of question.

这篇关于如何在 Struts 2 中实现分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 Struts 2 中实现分页

基础教程推荐