Skip to content

Commit

Permalink
检查插件是否被添加
Browse files Browse the repository at this point in the history
  • Loading branch information
yaokang committed Dec 28, 2023
1 parent 6440439 commit b6e029e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/com/github/pagehelper/PageInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ private Long count(Executor executor, MappedStatement ms, Object parameter,

@Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
Object wrapObjet = Plugin.wrap(target, this);
PageMethod.isAddToInterceptors = true;
return wrapObjet;
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/github/pagehelper/page/PageMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.github.pagehelper.ISelect;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageException;
import com.github.pagehelper.util.PageObjectUtil;

import java.util.Properties;
Expand All @@ -36,6 +37,7 @@
* @author liuzh
*/
public abstract class PageMethod {
public static volatile boolean isAddToInterceptors = false;
protected static final ThreadLocal<Page> LOCAL_PAGE = new ThreadLocal<Page>();
protected static boolean DEFAULT_COUNT = true;

Expand All @@ -45,6 +47,9 @@ public abstract class PageMethod {
* @param page
*/
public static void setLocalPage(Page page) {
if(!isAddToInterceptors){
throw new PageException("page helper not added to interceptors!");
}
LOCAL_PAGE.set(page);
}

Expand Down

0 comments on commit b6e029e

Please sign in to comment.