MyBatis的分页

来源:互联网 发布:淘宝贷款关闭后果严重 编辑:程序博客网 时间:2024/06/04 01:18

拦截器:拦截某些方法的调用,在方法执行前、后加上某些逻辑(代码)。

MyBatis的拦截器

分页拦截器需要继承mybatis自身的拦截器。intercept是主要的实现函数;plugin插件配置;setProperties加载配置文件(中的参数)。通过配置文件判断数据源,根据不同的方言进行夸数据库分页。

package org.apache.ibatis.plugin;import java.util.Properties;/** * @author Clinton Begin */public interface Interceptor {  Object intercept(Invocation invocation) throws Throwable;  Object plugin(Object target);  void setProperties(Properties properties);}

分页拦截器类

1、分页总数count在拦截器中计算,page.setCount()
2、根据方言不同,进行分页查询。即Dao层仅需要list查询。如MySql下 select * from user (limit start limit 在拦截器中组装了)

待完善
0 0
原创粉丝点击