The total number returned by mybatis-plus page paging is inconsistent with the actual number

Scenes:

In the project test, it was found that the data obtained by page paging return data getPages and getTotal is not consistent with the actual data. After clearing the database data to 0, the returned data actually returned 94 pieces of data;

solution:

Original code:

        final Page<EventEntity> page = new Page<>(dto.getPage(),dto.getPageSize());

After modification:

        final Page<EventEntity> page = new Page<>();
        page.setSize(dto.getPageSize());
        page.setCurrent(dto.getPage());
        page.setOptimizeCountSql(false);

Follow-up: This situation still occurs, you can only find all the records according to the conditions, and then page.setTotal the total number of all records, and perform manual pagination, which will cause a lot of loss of performance. If you have other solutions, please reply and let us know!

Guess you like

Origin blog.csdn.net/GuaGea/article/details/128582504