如何在Struts 2中实现分页 [英] How to implement a pagination in Struts 2

查看:152
本文介绍了如何在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 标签?

推荐答案

有一种方法可以实现它,我会给你一些建议。可能不是你正在寻找但显示标签我真的怀疑你可以实现一些不关心这个词的东西。 display标签是一个库,用于简化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, 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没有物。这分两步完成。首先检查希望返回的记录总数。它提供了在最后移动而不超过页面大小的可能性。然后返回在页面上表示所需的有限行数。这些都在显示表格的操作中完成。要工作的动作需要第一行和pagesize两个参数。如果记录总数发生变化,还需要更正导航器。

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中实现分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆