net.sourceforge.orm.mybatis.PaginationResultSetHandlerInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jweb-common Show documentation
Show all versions of jweb-common Show documentation
本项目主要弥补在使用mybatis3+springmvc+jquery easyui快速搭建web应用系统是遇到的框架不足.
主要工作包括:
1,扩展了ApplicationContextAware,通过单例注入spring容器,提供spring容器外的bean获取方法
2,扩展了apache shiro框架,统一了安全结构
3,扩展了mybatis3拦截器,在两个拦截器中自动完成分页注入,实现内存分页。
4,分页设计数据库方言
5,提供了一个easyuigrid的模型
6,提供了java泛型的jstl
7, xml工具包等一些小工具
The newest version!
package net.sourceforge.orm.mybatis;
import java.sql.Statement;
import java.util.Properties;
import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.reflection.DefaultReflectorFactory;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
import org.apache.ibatis.reflection.factory.ObjectFactory;
import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory;
import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;
import org.apache.ibatis.session.RowBounds;
/**
* @author [email protected]
**/
@Intercepts({ @Signature(type = ResultSetHandler.class, method = "handleResultSets", args = { Statement.class }) })
public class PaginationResultSetHandlerInterceptor implements Interceptor {
private static final ObjectFactory DEFAULT_OBJECT_FACTORY = new DefaultObjectFactory();
private static final ObjectWrapperFactory DEFAULT_OBJECT_WRAPPER_FACTORY = new DefaultObjectWrapperFactory();
private static final DefaultReflectorFactory DEFAULT_REFLECTOR_FACTORY = new DefaultReflectorFactory();
@Override
public Object intercept(Invocation invocation) throws Throwable {
Object resultSetHandler = invocation.getTarget();
MetaObject metaStatementHandler = MetaObject.forObject(resultSetHandler, DEFAULT_OBJECT_FACTORY, DEFAULT_OBJECT_WRAPPER_FACTORY, DEFAULT_REFLECTOR_FACTORY);
RowBounds rowBounds = (RowBounds) metaStatementHandler.getValue("rowBounds");
Object result = invocation.proceed();
if (rowBounds instanceof Page) {
metaStatementHandler.setValue("rowBounds.result", result);
}
return result;
}
@Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
}
@Override
public void setProperties(Properties properties) {
}
}