0

I am testing a Ext JS application (Client Side) and Play Framework (Service Side). I am using a grid in Ext JS with pagination.

The pagination part requires to send URL Query Parameters to my Play! server. This is no big deal, but how to process these parameters in the SQL Statement??

Example:

First request:

http://myDomain:9000/GetUsers?_dc=123456789&page=1&start=0&limit=25

Second reqeust:

http://myDomain:9000/GetUsers?_dc=123456789&page=2&start=25&limit=25

My thoughts: Normally in SQL you can set the TOP results:

SELECT TOP 25 FROM USERS

But how to translate the second request into a Sql query?

Thank you for taking time to help me out!

======>> EDIT: I am developing on SQL Server 2008, but I want this working on Sql Server 2005 or higher and Oracle 9 and higher :-)

4

2 回答 2

0

您可以尝试以下方法:

WITH Query_1 AS (
    SELECT
        Field1, Field2, etc
        ROW_NUMBER() OVER (ORDER BY Field1, Field2, etc) AS RowID
    FROM Table
    WHERE x=y
)
SELECT * FROM Query_1 WHERE RowID >= @start
AND RowID < @start + @limit

当然,ROW_NUMBER 在 SQL 2000 中并不存在,但由于您没有告诉我们您正在使用哪个SQL,我假设有更新的东西。

于 2011-08-31T21:47:09.980 回答
0

由于您使用的是 Play!框架,你应该做的是有一个合适的模型,实体代表你的 SQL 表。然后内置接收一系列结果:

// 25 max users start at 25
List<User> users = User.all().from(25).fetch(25);

您还应该查看分页模块。我还没有测试它,但它看起来正是你想要的。

于 2011-09-03T06:17:53.513 回答