Mybatis分页

分页有关:分页拦截插件、分页实体类、分页页面

分页插件:
拦截插件是一个拦截器,负责拦截符合条件的方法ID
拦截类具体方法:

/**
 * 
* 类名称:分页插件
* 类描述: 
* @author lyq
* @version 1.0
 */
@Intercepts({@Signature(type=StatementHandler.class,method="prepare",args={Connection.class})})
public class PagePlugin implements Interceptor {

	private static String dialect = "";	//数据库方言
	private static String pageSqlId = ""; //mapper.xml中需要拦截的ID(正则匹配)
	
	@Override
	public Object intercept(Invocation ivk) throws Throwable {
		// TODO Auto-generated method stub
		if(ivk.getTarget() instanceof RoutingStatementHandler){
			RoutingStatementHandler statementHandler = (RoutingStatementHandler)ivk.getTarget();
			BaseStatementHandler delegate = (BaseStatementHandler) ReflectHelper.getValueByFieldName(statementHandler, "delegate");
			MappedStatement mappedStatement = (MappedStatement) ReflectHelper.getValueByFieldName(delegate, "mappedStatement");
			
			if(mappedStatement.getId().matches(pageSqlId)){ //拦截需要分页的SQL
				BoundSql boundSql = delegate.getBoundSql();
				Object parameterObject = boundSql.getParameterObject();//分页SQL
		
  • 跳转
  • 首页
  • 上页
  • ${page.totalResult}
  • 跳转
  • 首页
  • 上页
  • ${str}
  • ${str}
  • ${str}
  • ${str}
  • 下页
  • 尾页
  • 下页
  • 尾页
  • 共${page.totalPage}页
  • 引用方式:
    <%@ include file="../tools/page.jsp"%>

    你可能感兴趣的:(java)