getUserLRowBounds();"; 3. Use the paging plug-in "PageHelper" to achieve it."/> getUserLRowBounds();"; 3. Use the paging plug-in "PageHelper" to achieve it.">
search
HomeCommon ProblemWhat are the several ways of paging in mybatis?

What are the several ways of paging in mybatis?

Mar 13, 2023 pm 01:52 PM
There are several types of mybatis paging

The three ways of paging in mybatis are: 1. Use Limit paging, with core statements such as "select * from users limit startIndex,pageSize;"; 2. Use RowBounds to implement paging, with statements such as "List getUserLRowBounds();"; 3. Use the paging plug-in "PageHelper" to achieve it.

What are the several ways of paging in mybatis?

The operating environment of this tutorial: Windows 10 system, Dell G3 computer.

What are the several ways of paging in mybatis?

MyBatis commonly used paging methods

Why pagination?

If the front-end needs to display data, due to the large amount of data and one-time display, a large amount of data will appear on the page, and the loading may not be completed, which is very inefficient. At this time, paged query This problem can be solved very well by displaying huge data according to a certain number, and you can also display other data by clicking on the next page or previous page, which is more efficient!

Let’s introduce several paging queries commonly used by mybatis!
First, take a look at all the data in the database. There are comments in the detailed code

What are the several ways of paging in mybatis?

##1. Use Limit paging
sql使用的核心语句
-- 语法:表示从startIndex下标开始,一页显示pageSize个
select * from users limit startIndex,pageSize;
-- 语法:表示显示[0,n]范围的数据
select * from users limit n;

Use Mybatis to implement paging and implement it based on sql

Writing interface

 //分页查询
    List<user> getUserLImit(Map<string> map);</string></user>
Writing Mapper.xml

<!--    分页查询-->
    <select>
        select * from firend_mq.users limit #{startIndex},#{pageSize}    </select>
Test class

    //测试分页查询
    @Test
    public  void getUserLImit(){
        SqlSession sqlSession = Mybatisutil.getSqlSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);

        Map<string> map = new HashMap();
        map.put("startIndex",0);
        map.put("pageSize",3);
        List<user> userLImit = mapper.getUserLImit(map);
        for (User user : userLImit) {
            System.out.println(user);
        }
        sqlSession.close();
    }</user></string>
Query Result:

What are the several ways of paging in mybatis?

2. RowBounds paging implementation

Based on RowBounds class object implementation, based on java code

Writing interface

//RowBounds实现分页查询
    List<user> getUserLRowBounds();</user>
Writing Mapper.xml, the query is actually all users

   <!--   RowBounds 分页查询-->
    <select>
        select * from firend_mq.users    </select>
Test class

    //RowBounds分页查询
    @Test
    public  void getUserLRowBounds(){
        SqlSession sqlSession = Mybatisutil.getSqlSession();
        //RowBounds对象  参数(起点,个数)
        RowBounds rowBounds = new RowBounds(2, 3);

        //通过java代码层面实现分页,第一个参数是接口类的方法路径
        List<user> userlist = sqlSession.selectList("dao.UserDao.getUserLRowBounds", null, rowBounds);
        for (User user : userlist) {
            System.out.println(user);
        }
        sqlSession.close();
    }</user>
Result:

What are the several ways of paging in mybatis?

3. Use the paging plug-in to achieve

What are the several ways of paging in mybatis?

#If you are interested, you can find out and post the official website link of the plug-in. There are official usage documents, learn about it by yourself

PageHelper paging plug-in

The above is the detailed content of What are the several ways of paging in mybatis?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools