PageHelper: syntax error, error in :'it 1 LIMIT ?'

created at 05-29-2022 views: 11

problem

The PageHelper method uses the static ThreadLocal parameter, and the paging parameter is bound to the thread.

This is safe as long as we guarantee that the MyBatis query method is immediately followed by the PageHelper method call. Because PageHelper automatically clears the object stored in ThreadLocal in the finally code segment.

The page of start in a thread does not guarantee that the thread has cleaned up the page variable when the current execution exits.

The paging process of a PageHelper is as follows:

  1. Set the page parameter
  2. Execute the query method
  3. In the Interceptor interface, check whether there is a set page parameter in ThreadLocal
  4. There is a page parameter, regenerate count sql and page sql, and execute the query. There is no page parameter, return the query result directly
  5. Execute LOCAL_PAGE.remove() to clear the page parameter

solution

Call PageHelper.clearPage() at the end of a method using PageHelper

created at:05-29-2022
edited at: 05-29-2022: