How use PagingAndSorting with MyBatis?

10,817

I was searching the same thing some weeks ago and seems this is not possible. For what i found you have to implement your own paginator using RowBound parameter

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

as explained in this answer that i'm sure you have already red How to do Pagination with mybatis?

Extending your mapper with PaginationAndSorting will not doing the job.

This project on github seems do what you are searching but i haven't try it and it has no comments, so i don't know if it's reliable and can be used as solution.

Share:
10,817
code4fun
Author by

code4fun

I'm not a genius. I only take a lot of pieces and build a puzzle.

Updated on June 04, 2022

Comments

  • code4fun
    code4fun almost 2 years

    I use mybatis for retriving data from the DB. But I would use the Pageable object (from spring) to have the pagination functionalities. Is this possible? It is still enough to extend myMapper with a PaginationAndSortRepository?

    Example:

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

    and then I use it from my service:

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

    The problem is that so I will return all MyObjects and not only the requested set.... I have to extract the interested list every time?

  • code4fun
    code4fun over 7 years
    Txs very much. I hoped in the solution. but It's ok. I will resolve it with extend my mapper manually.
  • code4fun
    code4fun over 7 years
    Txs. I don't have a mybatis-config.xml. How can I configure this? I only have a entry in my application properties: mybatis.mapperLocations=classpath*:**/mybatis/mappers/*.xml where points to the package that have the mappers.