spring - 如何在 MyBatis 中使用 PagingAndSorting?

标签 spring pagination mybatis spring-mybatis

我使用 mybatis 从数据库中检索数据。但是我会使用 Pageable 对象(来自 spring)来实现分页功能。这可能吗?用 PaginationAndSortRepository 扩展 myMapper 就足够了吗?

例子:

@Mapper
public interface MyObjetcMapper extends PagingAndSortingRepository {
    List<MyObjetc> findAllMyObjetcs(Pageable pageable);
}

然后我在我的服务中使用它:

List<MyObjetc> myObjetc= myObjetcMapper.findAllCharacteristics(pageable);
return new PageImpl<>(characteristics, new PageRequest(pageable.getPageNumber(), pageable.getPageSize(), pageable.getSort()), MyObjetc.size());

问题是我将返回所有 MyObjects 而不仅仅是请求的集合.... 我每次都必须提取感兴趣的列表?

最佳答案

几周前我在搜索同样的东西,但似乎这是不可能的。 对于我发现你必须使用 RowBound 参数实现你自己的分页器

(The RowBounds parameter causes MyBatis to skip the number of records specified, as well as limit the number of results returned to some number)

如本回答所述 我确定你已经变红了How to do Pagination with mybatis?

使用 PaginationAndSorting 扩展您的映射器将无法完成这项工作。

This project on github 似乎在做你正在搜索的事情,但我没有尝试过,也没有评论,所以我不知道它是否可靠,是否可以用作解决方案。

关于spring - 如何在 MyBatis 中使用 PagingAndSorting?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39718720/

相关文章:

spring - 我的 xml 配置有什么问题?

java - Spring ThreadPoolTask​​Executor 的线程计数始终为 1

jboss - MyBatis 与 JBoss 7.1 Web 应用程序集成

java - Mybatis 如何将另一个表中的列映射到字符串列表?

java - Spring Integration 无法 Autowiring 字段

java - 在 URL 中附加特殊字符

javascript - 更改上一页和下一页以进行分页,具有过滤功能

php在使用分页脚本时获取帖子数据

java - Cassandra 分页如何处理并发插入

caching - 外部刷新 MyBatis 缓存(映射器之外)