Home > Back-end >  Use mybatis, want to take advantage of the spring data Pageable problem
Use mybatis, want to take advantage of the spring data Pageable problem

Time:04-08

See a lot of people have mentioned on the website use Pageable paging query, but most are JPA, I used here is mybatis, controller code:
@ GetMapping
Public Object GetVacations (
@ PageableDefault (page=2, size=4, sort={} "id, desc") Pageable Pageable) {
List Vacations=new ArrayList<> (a);

For vacations.=vacationMapper getVacations (pageable);

Return for vacations.
}

Mapper code is such,
@ the Select (" Select * FROM VACATION WHERE state='has been off the order by ${sort} limit ${page}, ${size} ")
List GetVacations (Pageable Pageable);

Modified to:
@ the Select (" Select * FROM VACATION WHERE state='has been off the order by id limit ${page}, ${size} ")
List GetVacations (Pageable Pageable);
Can run, I function is achieved, is now want to know the sort used here, see PageableDefault annotations to the source code, this sort is a String [], an array type,
There are two problems:
1 is in mybatis query processing of the parameters of the array?
2 this case whether there is any other way, on the Internet to see some people in the select statement does not apply the three parameters, I also tried, such pageable doesn't work, don't know how to get paging information, they are going to do?

CodePudding user response:

Mybatis paging suggest using PageHelper

CodePudding user response:

Not limit ${page}, ${size}
"But limit ${offset}, ${size}
")
Page not found a good plug-in, felling oneself write more appropriate

I had originally thought that the spring pageable, can be independent of the mapper. XML
As long as the mapper configuration query
Can automatically calculate the total
  • Related