Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How use PagingAndSorting with MyBatis?

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?

like image 824
code4fun Avatar asked Dec 02 '25 06:12

code4fun


1 Answers

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.

like image 164
amicoderozer Avatar answered Dec 03 '25 23:12

amicoderozer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!