`

MyBatis 通用分页

阅读更多

分页分为真分页和假分页,而 MyBatis 本身没有提供基于数据库方言的分页功能,而是基于 JDBC 的游标分页,很容易出现性能问题。网上提供的一个解决方案感觉还不错,是基于 MyBatis 本身的插件机制,通过拦截 Sql 做分页。

         首先,我们需要根据不同数据库来加载不同的分页 SQL ,这里我们参考 Hibernate ,定义一个数据库方言接口

Dialect.java

package com.iflytek.mybatis.page.dialect;

/**
 * @author xdwang
 * 
 * @ceate 2012-12-19 下午7:45:24
 * 
 * @description 数据库方言接口
 * 
 */

public interface Dialect {

	public static enum Type {
		MYSQL {
			public String getValue() {
				return "mysql";
			}
		},
		MSSQL {
			public String getValue() {
				return "sqlserver";
			}
		},
		ORACLE {
			public String getValue() {
				return "oracle";
			}
		}
	}

	/**
	 * @descrption 获取分页SQL
	 * @author xdwang
	 * @create 2012-12-19下午7:48:44
	 * @param sql
	 *            原始查询SQL
	 * @param offset
	 *            开始记录索引(从零开始)
	 * @param limit
	 *            每页记录大小
	 * @return 返回数据库相关的分页SQL语句
	 */
	public abstract String getPageSql(String sql, int offset, int limit);

}

 然后分别定义不同类型数据库的具体分页,这里我们列举3个比较常用的,MySQL、MSSQL、Oracle
MySql5Dialect.java

package com.iflytek.mybatis.page.dialect;

/**
 * @author xdwang
 * 
 * @ceate 2012-12-19 下午7:50:44
 * 
 * @description MySQL数据库实现
 * 
 */
public class MySql5Dialect implements Dialect {

	protected static final String SQL_END_DELIMITER = ";";

	public String getPageSql(String sql, boolean hasOffset) {
		return MySql5PageHepler.getPageSql(sql, -1, -1);
	}

	public String getPageSql(String sql, int offset, int limit) {
		return MySql5PageHepler.getPageSql(sql, offset, limit);
	}

	public boolean supportsLimit() {
		return true;
	}
}

 MySql5PageHepler.java

package com.iflytek.mybatis.page.dialect;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 
 * @author xdwang
 * 
 * @ceate 2012-12-19 下午8:41:21
 * 
 * @description MySql辅助方法
 * 
 */
public class MySql5PageHepler {

	/**
	 * @descrption 得到查询总数的sql
	 * @author xdwang
	 * @create 2012-12-19下午8:41:10
	 * @param querySelect
	 * @return
	 */
	public static String getCountString(String querySelect) {

		querySelect = getLineSql(querySelect);
		int orderIndex = getLastOrderInsertPoint(querySelect);

		int formIndex = getAfterFormInsertPoint(querySelect);
		String select = querySelect.substring(0, formIndex);

		// 如果SELECT 中包含 DISTINCT 只能在外层包含COUNT
		if (select.toLowerCase().indexOf("select distinct") != -1 || querySelect.toLowerCase().indexOf("group by") != -1) {
			return new StringBuffer(querySelect.length()).append("select count(1) count from (").append(querySelect.substring(0, orderIndex)).append(" ) t").toString();
		} else {
			return new StringBuffer(querySelect.length()).append("select count(1) count ").append(querySelect.substring(formIndex, orderIndex)).toString();
		}
	}

	/**
	 * 得到最后一个Order By的插入点位置
	 * 
	 * @return 返回最后一个Order By插入点的位置
	 */
	private static int getLastOrderInsertPoint(String querySelect) {
		int orderIndex = querySelect.toLowerCase().lastIndexOf("order by");
		if (orderIndex == -1 || !isBracketCanPartnership(querySelect.substring(orderIndex, querySelect.length()))) {
			throw new RuntimeException("My SQL 分页必须要有Order by 语句!");
		}
		return orderIndex;
	}

	/**
	 * 得到分页的SQL
	 * 
	 * @param offset
	 *            偏移量
	 * @param limit
	 *            位置
	 * @return 分页SQL
	 */
	public static String getPageSql(String querySelect, int offset, int limit) {

		querySelect = getLineSql(querySelect);

		String sql = querySelect.replaceAll("[^\\s,]+\\.", "") + " limit " + offset + " ," + limit;

		return sql;

	}

	/**
	 * 将SQL语句变成一条语句,并且每个单词的间隔都是1个空格
	 * 
	 * @param sql
	 *            SQL语句
	 * @return 如果sql是NULL返回空,否则返回转化后的SQL
	 */
	private static String getLineSql(String sql) {
		return sql.replaceAll("[\r\n]", " ").replaceAll("\\s{2,}", " ");
	}

	/**
	 * 得到SQL第一个正确的FROM的的插入点
	 */
	private static int getAfterFormInsertPoint(String querySelect) {
		String regex = "\\s+FROM\\s+";
		Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
		Matcher matcher = pattern.matcher(querySelect);
		while (matcher.find()) {
			int fromStartIndex = matcher.start(0);
			String text = querySelect.substring(0, fromStartIndex);
			if (isBracketCanPartnership(text)) {
				return fromStartIndex;
			}
		}
		return 0;
	}

	/**
	 * 判断括号"()"是否匹配,并不会判断排列顺序是否正确
	 * 
	 * @param text
	 *            要判断的文本
	 * @return 如果匹配返回TRUE,否则返回FALSE
	 */
	private static boolean isBracketCanPartnership(String text) {
		if (text == null || (getIndexOfCount(text, '(') != getIndexOfCount(text, ')'))) {
			return false;
		}
		return true;
	}

	/**
	 * 得到一个字符在另一个字符串中出现的次数
	 * 
	 * @param text
	 *            文本
	 * @param ch
	 *            字符
	 */
	private static int getIndexOfCount(String text, char ch) {
		int count = 0;
		for (int i = 0; i < text.length(); i++) {
			count = (text.charAt(i) == ch) ? count + 1 : count;
		}
		return count;
	}
}

 

 OracleDialect.java

package com.iflytek.mybatis.page.dialect;

/**
 * @author xdwang
 * 
 * @ceate 2012-12-19 下午7:54:56
 * 
 * @description Oracle数据库实现
 * 
 */
public class OracleDialect implements Dialect {

	public String getPageSql(String sql, int offset, int limit) {
		sql = sql.trim();
		boolean isForUpdate = false;
		if (sql.toLowerCase().endsWith(" for update")) {
			sql = sql.substring(0, sql.length() - 11);
			isForUpdate = true;
		}

		StringBuffer pageSql = new StringBuffer(sql.length() + 100);
		pageSql.append("select * from ( select row_.*, rownum rownum_ from ( ");
		pageSql.append(sql);
		pageSql.append(" ) row_ ) where rownum_ > " + offset + " and rownum_ <= " + (offset + limit));
		if (isForUpdate) {
			pageSql.append(" for update");
		}
		return pageSql.toString();
	}

}

 

SQLServerDialect.java

package com.iflytek.mybatis.page.dialect;

/**
 * @author xdwang
 * 
 * @ceate 2012-12-19 下午7:53:14
 * 
 * @description SQLServer数据库实现
 * 
 */
public class SQLServerDialect implements Dialect {

	public String getPageSql(String sql, int offset, int limit) {
		sql = sql.trim();
		StringBuffer pageSql = new StringBuffer(sql.length() + 100);
		// 其实这里还是有一点问题的,就是排序问题,指定死了,有解决的提供一下,等复习到Hibernate看看Hibernat内部是如何实现的。
		pageSql.append("select * from(select a.*,row_number() over (order by id desc) rownum from( ");
		pageSql.append(sql);
		pageSql.append(") a )b where rownum> " + offset + " and rownum <= " + (offset + limit));
		return pageSql.toString();
	}

}

 

然后我们定义拦截器
PaginationInterceptor.java

package com.iflytek.mybatis.page.interceptor;

import java.sql.Connection;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.BoundSql;
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.MetaObject;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.RowBounds;

import com.iflytek.mybatis.page.dialect.Dialect;
import com.iflytek.mybatis.page.dialect.MySql5Dialect;
import com.iflytek.mybatis.page.dialect.OracleDialect;

/**
 * 
 * @author xdwang
 * 
 * @ceate 2012-12-19 下午8:01:31
 * 
 * @description 然后就是实现mybatis提供的拦截器接口,编写我们自己的分页实现,原理就是拦截底层JDBC操作相关的Statement对象,
 *              把前端的分页参数如当前记录索引和每页大小通过拦截器注入到sql语句中
 *              ,即在sql执行之前通过分页参数重新生成分页sql,而具体的分页sql实现是分离到Dialect接口中去。
 * 
 * 
 */
@Intercepts({ @Signature(type = StatementHandler.class, method = "prepare", args = { Connection.class }) })
public class PaginationInterceptor implements Interceptor {

	private final static Log log = LogFactory.getLog(PaginationInterceptor.class);

	public Object intercept(Invocation invocation) throws Throwable {
		StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
		BoundSql boundSql = statementHandler.getBoundSql();
		MetaObject metaStatementHandler = MetaObject.forObject(statementHandler);
		RowBounds rowBounds = (RowBounds) metaStatementHandler.getValue("delegate.rowBounds");
		if (rowBounds == null || rowBounds == RowBounds.DEFAULT) {
			return invocation.proceed();
		}
		Configuration configuration = (Configuration) metaStatementHandler.getValue("delegate.configuration");
		Dialect.Type databaseType = null;
		try {
			databaseType = Dialect.Type.valueOf(configuration.getVariables().getProperty("dialect").toUpperCase());
		} catch (Exception e) {
			// ignore
		}
		if (databaseType == null) {
			throw new RuntimeException("the value of the dialect property in configuration.xml is not defined : " + configuration.getVariables().getProperty("dialect"));
		}
		Dialect dialect = null;
		switch (databaseType) {
		case MYSQL:
			dialect = new MySql5Dialect();
			break;
		case MSSQL:
			dialect = new MySql5Dialect();
			break;
		case ORACLE:
			dialect = new OracleDialect();
			break;
		default:
			dialect = new MySql5Dialect();
		}

		String originalSql = (String) metaStatementHandler.getValue("delegate.boundSql.sql");
		metaStatementHandler.setValue("delegate.boundSql.sql", dialect.getPageSql(originalSql, rowBounds.getOffset(), rowBounds.getLimit()));
		metaStatementHandler.setValue("delegate.rowBounds.offset", RowBounds.NO_ROW_OFFSET);
		metaStatementHandler.setValue("delegate.rowBounds.limit", RowBounds.NO_ROW_LIMIT);
		if (log.isDebugEnabled()) {
			log.debug("生成分页SQL : " + boundSql.getSql());
		}
		return invocation.proceed();
	}

	public Object plugin(Object target) {
		return Plugin.wrap(target, this);
	}

	public void setProperties(Properties properties) {
	}

}

 

Ok,搞定了,下面看看如何使用,其实和直接调用MyBatis原生的假分页方式一样。只需要在mybatis-config.xml添加一个标识和一个插件

	<properties>
		<property name="dialect" value="mysql" />
	</properties>

	<plugins>
		<plugin interceptor="com.iflytek.mybatis.page.interceptor.PaginationInterceptor">
		</plugin>
	</plugins>

 然后和MyBatis默认提供分页的方式一样,直接调用

	public List<Student> getStudentsByPage(){
		List<Student> students = new ArrayList<Student>();
		SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
		try {
			//从第一条开始,取4条记录
			RowBounds rowBounds = new RowBounds(1,4);
			Student student=new Student();
			student.setName("xdwang");
			students = sqlSession.selectList("com.iflytek.dao.mapper.StudentMapper.selectByPageList", student, rowBounds);
			sqlSession.commit();
		} finally {
			sqlSession.close();
		}
		return students;
		
	}

 

Ok ,搞定,当然,上面我们也可以将需要拦截添加的 Sql 写在 mapper.xml 中,然后再需要分页的查询语句中引用,只是需要在每个模块下分页的地方都引用,相对来说比较麻烦点(其实也还好)。

 

 

 

分享到:
评论
5 楼 willpan___ 2014-01-11  
收藏
4 楼 KeepMoving龙强 2013-10-19  
这是我引用myibatis配置文件报的错误:

  Cause: org.xml.sax.SAXParseException: The content of element type "configura
tion" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFact
ory?,plugins?,environments?,databaseIdProvider?,mappers?)".
3 楼 KeepMoving龙强 2013-10-19  
楼主,你mybiats配置文件没有报错吗???


2013-10-19 13:45:02 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production enviro
nments was not found on the java.library.path: C:\Users\Administrator\AppData\Local\Genuitec\Common\
binary\com.sun.java.jdk.win32.x86_1.6.0.013\bin;E:\apache-tomcat-6.0.36\bin
2013-10-19 13:45:03 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8089
2013-10-19 13:45:03 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 755 ms
2013-10-19 13:45:03 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2013-10-19 13:45:03 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.36
2013-10-19 13:45:03 org.apache.catalina.startup.HostConfig deployDescriptor
信息: Deploying configuration descriptor host-manager.xml
2013-10-19 13:45:03 org.apache.catalina.startup.HostConfig deployDescriptor
信息: Deploying configuration descriptor manager.xml
2013-10-19 13:45:03 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory docs
2013-10-19 13:45:03 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory examples
2013-10-19 13:45:04 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2013-10-19 13:45:04 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2013-10-19 13:45:04 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory fms
2013-10-19 13:45:10 org.apache.catalina.core.ApplicationContext log
信息: Set web app root system property: 'webapp.root' = [E:\apache-tomcat-6.0.36\webapps\fms\]
2013-10-19 13:45:10 org.apache.catalina.core.ApplicationContext log
信息: Initializing log4j from [classpath:/log4j.properties]
2013-10-19 13:45:10 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
[INFO][main] 13:45:10 - Root WebApplicationContext: initialization started
[INFO][main] 13:45:10 - Refreshing Root WebApplicationContext: startup date [Sat Oct 19 13:45:10 CST
2013]; root of context hierarchy
[INFO][main] 13:45:11 - Loading XML bean definitions from class path resource [spring/ApplicationCon
text.xml]
[INFO][main] 13:45:11 - Loading XML bean definitions from class path resource [spring/spring-jdbc.xm
l]
[INFO][main] 13:45:11 - Loading XML bean definitions from class path resource [spring/spring-action-
service-dao.xml]
[INFO][main] 13:45:11 - Loading XML bean definitions from class path resource [spring/base/spring-ba
se.xml]
[INFO][main] 13:45:11 - Loading XML bean definitions from class path resource [spring/gaim/spring-ga
im.xml]
[INFO][main] 13:45:11 - Loading XML bean definitions from class path resource [spring/report/spring-
report.xml]
[INFO][main] 13:45:13 - Loading properties file from class path resource [Config.properties]
[INFO][main] 13:45:13 - Pre-instantiating singletons in org.springframework.beans.factory.support.De
faultListableBeanFactory@13ccea: defining beans [configure,initFMS,fmsCache,serialNoGen,actionInterc
eptor,appContext,dataSource,sqlExecutor,baseMyDao,baseDao,sqlMapClient,sqlSessionFactory,sqlSession,
transactionManager,txAdvice,org.springframework.aop.config.internalAutoProxyCreator,serviceOperation
,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,userAction,roleAction,paramActi
on,messageAction,menuAction,logAction,bankAction,userService,roleService,paramService,messageService
,logService,menuService,bankService,userDao,roleDao,paramDao,messageDao,messageMyDao,logDao,menuDao,
bankDao,gaimAction,gaimMsgService,gaimMsgDao,reportAction,reportService]; root of factory hierarchy
2013-10-19 13:45:15 net.sf.ehcache.config.ConfigurationFactory parseConfiguration
警告: No configuration found. Configuring ehcache from ehcache-failsafe.xml  found in the classpath: j
ar:file:/E:/apache-tomcat-6.0.36/webapps/fms/WEB-INF/lib/ehcache-core-2.3.0.jar!/ehcache-failsafe.xm
l
[INFO][main] 13:45:16 - Destroying singletons in org.springframework.beans.factory.support.DefaultLi
stableBeanFactory@13ccea: defining beans [configure,initFMS,fmsCache,serialNoGen,actionInterceptor,a
ppContext,dataSource,sqlExecutor,baseMyDao,baseDao,sqlMapClient,sqlSessionFactory,sqlSession,transac
tionManager,txAdvice,org.springframework.aop.config.internalAutoProxyCreator,serviceOperation,org.sp
ringframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,userAction,roleAction,paramAction,mess
ageAction,menuAction,logAction,bankAction,userService,roleService,paramService,messageService,logSer
vice,menuService,bankService,userDao,roleDao,paramDao,messageDao,messageMyDao,logDao,menuDao,bankDao
,gaimAction,gaimMsgService,gaimMsgDao,reportAction,reportService]; root of factory hierarchy
[ERROR][main] 13:45:16 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'initFMS' def
ined in class path resource [spring/ApplicationContext.xml]: Initialization of bean failed; nested e
xception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '
messageMyDao' defined in class path resource [spring/base/spring-base.xml]: Initialization of bean f
ailed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating b
ean with name 'sqlSessionFactory' defined in class path resource [spring/spring-jdbc.xml]: Invocatio
n of init method failed; nested exception is org.apache.ibatis.builder.BuilderException: Error creat
ing document instance.  Cause: org.xml.sax.SAXParseException: The content of element type "configura
tion" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFact
ory?,plugins?,environments?,databaseIdProvider?,mappers?)".
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstra
ctAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abstract
AutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.ja
va:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingl
etonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java
:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:1
93)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(De
faultListableBeanFactory.java:609)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(A
bstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContex
t.java:469)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLo
ader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.j
ava:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'm
essageMyDao' defined in class path resource [spring/base/spring-base.xml]: Initialization of bean fa
iled; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating be
an with name 'sqlSessionFactory' defined in class path resource [spring/spring-jdbc.xml]: Invocation
of init method failed; nested exception is org.apache.ibatis.builder.BuilderException: Error creati
ng document instance.  Cause: org.xml.sax.SAXParseException: The content of element type "configurat
ion" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFacto
ry?,plugins?,environments?,databaseIdProvider?,mappers?)".
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstra
ctAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abstract
AutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.ja
va:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingl
etonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java
:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:1
93)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(Abst
ractAutowireCapableBeanFactory.java:1136)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(Abstra
ctAutowireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstra
ctAutowireCapableBeanFactory.java:517)
... 35 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 's
qlSessionFactory' defined in class path resource [spring/spring-jdbc.xml]: Invocation of init method
failed; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document ins
tance.  Cause: org.xml.sax.SAXParseException: The content of element type "configuration" must match
"(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,plugins?,en
vironments?,databaseIdProvider?,mappers?)".
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(Abst
ractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstra
ctAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abstract
AutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.ja
va:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingl
etonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java
:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:1
93)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(Abst
ractAutowireCapableBeanFactory.java:1136)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(Abstra
ctAutowireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstra
ctAutowireCapableBeanFactory.java:517)
... 43 more
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org
.xml.sax.SAXParseException: The content of element type "configuration" must match "(properties?,set
tings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,plugins?,environments?,databa
seIdProvider?,mappers?)".
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:253)
at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:122)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.<init>(XMLConfigBuilder.java:72)
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:287)
at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:269)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(A
bstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(Abst
ractAutowireCapableBeanFactory.java:1452)
... 52 more
Caused by: org.xml.sax.SAXParseException: The content of element type "configuration" must match "(p
roperties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,plugins?,enviro
nments?,databaseIdProvider?,mappers?)".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandler
Wrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.jav
a:2017)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:901)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumen
tFragmentScannerImpl.java:1774)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.nex
t(XMLDocumentFragmentScannerImpl.java:2930)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:
648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentF
ragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:251)
... 58 more
2013-10-19 13:45:16 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.we
b.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'initFMS' def
ined in class path resource [spring/ApplicationContext.xml]: Initialization of bean failed; nested e
xception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '
messageMyDao' defined in class path resource [spring/base/spring-base.xml]: Initialization of bean f
ailed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating b
ean with name 'sqlSessionFactory' defined in class path resource [spring/spring-jdbc.xml]: Invocatio
n of init method failed; nested exception is org.apache.ibatis.builder.BuilderException: Error creat
ing document instance.  Cause: org.xml.sax.SAXParseException: The content of element type "configura
tion" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFact
ory?,plugins?,environments?,databaseIdProvider?,mappers?)".
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstra
ctAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abstract
AutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.ja
va:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingl
etonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java
:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:1
93)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(De
faultListableBeanFactory.java:609)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(A
bstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContex
t.java:469)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLo
ader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.j
ava:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'm
essageMyDao' defined in class path resource [spring/base/spring-base.xml]: Initialization of bean fa
iled; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating be
an with name 'sqlSessionFactory' defined in class path resource [spring/spring-jdbc.xml]: Invocation
of init method failed; nested exception is org.apache.ibatis.builder.BuilderException: Error creati
ng document instance.  Cause: org.xml.sax.SAXParseException: The content of element type "configurat
ion" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFacto
ry?,plugins?,environments?,databaseIdProvider?,mappers?)".
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstra
ctAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abstract
AutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.ja
va:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingl
etonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java
:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:1
93)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(Abst
ractAutowireCapableBeanFactory.java:1136)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(Abstra
ctAutowireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstra
ctAutowireCapableBeanFactory.java:517)
... 35 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 's
qlSessionFactory' defined in class path resource [spring/spring-jdbc.xml]: Invocation of init method
failed; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document ins
tance.  Cause: org.xml.sax.SAXParseException: The content of element type "configuration" must match
"(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,plugins?,en
vironments?,databaseIdProvider?,mappers?)".
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(Abst
ractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstra
ctAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abstract
AutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.ja
va:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingl
etonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java
:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:1
93)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(Abst
ractAutowireCapableBeanFactory.java:1136)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(Abstra
ctAutowireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstra
ctAutowireCapableBeanFactory.java:517)
... 43 more
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org
.xml.sax.SAXParseException: The content of element type "configuration" must match "(properties?,set
tings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,plugins?,environments?,databa
seIdProvider?,mappers?)".
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:253)
at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:122)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.<init>(XMLConfigBuilder.java:72)
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:287)
at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:269)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(A
bstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(Abst
ractAutowireCapableBeanFactory.java:1452)
... 52 more
Caused by: org.xml.sax.SAXParseException: The content of element type "configuration" must match "(p
roperties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,plugins?,enviro
nments?,databaseIdProvider?,mappers?)".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandler
Wrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.jav
a:2017)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:901)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumen
tFragmentScannerImpl.java:1774)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.nex
t(XMLDocumentFragmentScannerImpl.java:2930)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:
648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentF
ragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:251)
... 58 more
2013-10-19 13:45:16 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2013-10-19 13:45:16 org.apache.catalina.core.StandardContext start
严重: Context [/fms] startup failed due to previous errors
2013-10-19 13:45:16 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
2013-10-19 13:45:16 org.apache.catalina.core.ApplicationContext log
信息: Shutting down log4j
2013-10-19 13:45:16 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/fms] appears to have started a thread named [net.sf.ehcache.CacheManager@1
9a274f] but has failed to stop it. This is very likely to create a memory leak.
2013-10-19 13:45:17 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory ROOT
2013-10-19 13:45:17 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8089
2013-10-19 13:45:17 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2013-10-19 13:45:17 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/31  config=null
2013-10-19 13:45:17 org.apache.catalina.startup.Catalina start
信息: Server startup in 14185 ms
2013-10-19 13:45:18 org.apache.catalina.loader.WebappClassLoader findResourceInternal
信息: Illegal access: this web application instance has been stopped already.  Could not load ehcache-
version.properties.  The eventual following stack trace is caused by an error thrown for debugging p
urposes as well as to attempt to terminate the thread which caused the illegal access, and has no fu
nctional impact.
2 楼 zhuchao_ko 2013-02-01  
1 楼 QQ371496669 2013-01-25  
楼主辛苦!!!非常感谢!!!

相关推荐

    Mybatis通用分页插件

    Mybatis通用分页插件是Java开发中广泛使用的ORM(对象关系映射)框架扩展,主要针对Mybatis进行优化,提供了高效便捷的分页功能。这个插件的目的是简化在数据库查询时的分页操作,使得开发者能够更专注于业务逻辑,...

    06实现mybatis分页插件demo

    06实现mybatis分页插件demo06实现mybatis分页插件demo06实现mybatis分页插件demo06实现mybatis分页插件demo06实现mybatis分页插件demo06实现mybatis分页插件demo06实现mybatis分页插件demo06实现mybatis分页插件demo...

    Java_Mybatis通用分页插件.zip

    Java Mybatis通用分页插件是为了解决在Mybatis框架中进行数据查询时的分页问题而设计的。在大型应用中,由于数据量庞大,一次性加载所有数据不仅会消耗大量内存,还可能导致用户界面响应变慢。因此,分页查询成为了...

    基于Java的Mybatis通用分页插件设计源码

    该项目为Java语言开发的Mybatis通用分页插件,包含137个文件,其中Java源文件84个、XML配置文件35个、SQL文件7个,并附带少量Markdown、properties和LICENSE文件。

    springmvc+mybatis通用分页

    总的来说,整合SpringMVC和MyBatis并实现通用分页,需要理解这两个框架的工作原理,掌握它们的配置,以及如何在Java代码中使用它们。同时,对于分页功能,需要理解数据库的分页机制,并能将其应用到实际的SQL查询中...

    mybatis 通用分页插件和批量操作插件

    NULL 博文链接:https://hzs0502030128.iteye.com/blog/2254585

    (四)struts2- 2.3.15.3 spring3.2.4 mybatis-3.2.3 通用分页(不同数据库) 拦截器(2014-01-27 17:16)

    总的来说,这个项目展示了如何在Java Web环境中,利用Struts2、Spring和MyBatis三大框架,构建一个具备通用分页和拦截器功能的应用,为开发者提供了跨数据库的分页解决方案。通过学习和理解这个示例,开发者可以更好...

    mybatis逻辑分页,含分页导航

    综上所述,MyBatis通过动态SQL实现了逻辑分页,这使得我们可以在多种数据库环境下编写通用的分页查询。同时,结合Java代码,我们可以轻松实现分页导航功能,提升用户在大量数据浏览时的体验。在提供的`pagination-...

    ibatis struts2 spring3 mybatis 分页 crud 完整代码

    这里我们讨论的是一个基于Ibatis、Struts2、Spring3的整合应用,涵盖了数据访问、业务逻辑和控制层的关键技术,以及分页和CRUD操作的实现。下面我们将详细探讨这些知识点。 1. **Ibatis**:Ibatis是一个优秀的持久...

    Mybatis-PageHelper:Mybatis通用分页插件

    MyBatis分页-PageHelper如果您使用的是MyBatis,建议尝试使用此分页插件。 这必须是最方便的分页插件。 PageHelper支持任何复杂的单表,多表查询。 关于某些特殊情况,请参阅。 要使用PageHelper吗? 请查看 。新的...

    spring-boot-集成mybatis带分页page

    # Spring Boot 集成 MyBatis, 分页插件 PageHelper, 通用 Mapper ## 项目依赖 ```xml &lt;!--mybatis--&gt; &lt;groupId&gt;org.mybatis.spring.boot &lt;artifactId&gt;mybatis-spring-boot-starter &lt;version&gt;1.1.1 &lt;!...

    Mybatis-PageHelper:Mybatis通用分页插件

    MyBatis Pagination - PageHelper If you are using MyBatis, it is recommended to try this pagination plugin. This must be the MOST CONVENIENT pagination plugin. PageHelper supports any complex single-...

    springboot整合mybatis集成分页查询事务配置,页面模板

    - 拦截器在MyBatis-SpringBoot中可以用来实现一些通用功能,比如日志记录、权限验证等。需要定义一个实现了`Interceptor`接口的类,并在`mybatis-config.xml`中配置。 - 在SpringBoot中,拦截器可以与Spring MVC的...

    springmvc+mybatis+分页整合

    本项目中的分页实现可能采用了通用的PageHelper或者MyBatis-Plus等插件。这些插件通常提供拦截器,可以在执行SQL时自动添加LIMIT和OFFSET子句,实现数据库级别的分页。开发者只需在Service或Mapper接口中设置页码和...

    基于Mybatis的分页插件工具设计源码

    本源码为基于Mybatis的分页插件工具设计,包含38个Java文件、5...该项目旨在为Mybatis用户提供一个通用、高效的分页插件解决方案,支持12种数据库,通过最少的代码完成分页数据读取,适用于目前主流数据库的使用场景。

    Spring集成MyBatis 通用Mapper以及 pagehelper分页插件

    通用Mapper和PageHelper则是MyBatis生态中的实用工具,可以进一步简化数据库操作和实现高效的分页功能。下面将详细阐述这些知识点。 首先,Spring是一个全功能的开源应用框架,它提供了依赖注入(Dependency ...

    修改后的Mybatis - 通用分页拦截器

    //分页 PageHelper.startPageTable(start, length); List&lt;XofoWork&gt; works= workMapper.selectByBean(mapBean); EUDataGridResult result = new EUDataGridResult(); result.setData(works); //取记录总条数 Page...

Global site tag (gtag.js) - Google Analytics