如何做与mybatis分页? [英] How to do Pagination with mybatis?

查看:112
本文介绍了如何做与mybatis分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个电子商务应用程序,在这个应用程序中我必须展示一个使用搜索功能的可用产品列表。



与每个搜索一样,我必须实现分页这里。



我使用mybatis作为我的ORM工具,并将mysql作为底层数据库。



找到以下方法来完成此任务:


  1. 客户端分页
    :将不得不一次从匹配搜索条件的数据库获取所有结果,并在我的代码级别处理分页(可能是叶末结束代码)。

  2. 服务器端分页
    使用mysql,我可以使用Limit和结果集的偏移量来构造查询例如:
    SELECT * FROM sampletable WHERE condition1> 1 AND condition2> 2 LIMIT 0,20


在这里,每当用户在搜索结果中导航时选择一个新页面,我必须通过偏移和限制计数。



任何人都可以告诉,


  1. 这将是更好的实现分页的方式吗? mybatis支持一个更好的方式来实现分页,而不仅仅依赖于上面的SQL查询(比如hibernate标准API)。


    任何输入都非常容易理解。
    Thanks。

    解决方案

    我自己在sql查询中使用LIMIT的第二个opion。 b

    但是有一系列支持使用RowBounds类的分页方法。
    这在mybatis文档这里中有详细描述



    注意使用正确的结果集类型。


    I am currently working on a ecommerce application where I have to show a list of available products using search functionality.

    As with every search, I have to implement Pagination here.

    I am using mybatis as my ORM tool and mysql as an underlying database.

    Googling around I found following ways to accomplish this task :

    1. Client Side paging : Here I will have to fetch all the results from the database matching the search criteria in one stroke and handle the pagination at my code level (Possibly frond end code ).

    2. Server Side Paging : With mysql I can use the Limit and the offset of the resultset to construct a query like : SELECT * FROM sampletable WHERE condition1>1 AND condition2>2 LIMIT 0,20

    Here, I have to pass the offset and limit count everytime the user selects a new page while navigating in search results.

    Can anyone tell,

    1. which will be better way to implement paging ?
    2. Do mybatis supports a better way to implement paging than just relying on above SQL queries ( like the hibernate criteria APIs).

    Any inputs is highly appreaciated. Thanks .

    解决方案

    I myself use your second opion with LIMIT in sql query.

    But there is range of methods that support pagination using RowBounds class. This is well described in mybatis documentation here

    Pay attention to correct result set type to use.

    这篇关于如何做与mybatis分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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