- 浏览: 979990 次
文章分类
- 全部博客 (428)
- Hadoop (2)
- HBase (1)
- ELK (1)
- ActiveMQ (13)
- Kafka (5)
- Redis (14)
- Dubbo (1)
- Memcached (5)
- Netty (56)
- Mina (34)
- NIO (51)
- JUC (53)
- Spring (13)
- Mybatis (17)
- MySQL (21)
- JDBC (12)
- C3P0 (5)
- Tomcat (13)
- SLF4J-log4j (9)
- P6Spy (4)
- Quartz (12)
- Zabbix (7)
- JAVA (9)
- Linux (15)
- HTML (9)
- Lucene (0)
- JS (2)
- WebService (1)
- Maven (4)
- Oracle&MSSQL (14)
- iText (11)
- Development Tools (8)
- UTILS (4)
- LIFE (8)
最新评论
-
Donald_Draper:
Donald_Draper 写道刘落落cici 写道能给我发一 ...
DatagramChannelImpl 解析三(多播) -
Donald_Draper:
刘落落cici 写道能给我发一份这个类的源码吗Datagram ...
DatagramChannelImpl 解析三(多播) -
lyfyouyun:
请问楼主,执行消息发送的时候,报错:Transport sch ...
ActiveMQ连接工厂、连接详解 -
ezlhq:
关于 PollArrayWrapper 状态含义猜测:参考 S ...
WindowsSelectorImpl解析一(FdMap,PollArrayWrapper) -
flyfeifei66:
打算使用xmemcache作为memcache的客户端,由于x ...
Memcached分布式客户端(Xmemcached)
SqlSessionFactory初始化:http://donald-draper.iteye.com/blog/2331917
Mybatis加载解析Mapper(xml)文件第一讲:http://donald-draper.iteye.com/blog/2333125
Mybatis加载解析Mapper(xml)文件第二讲:http://donald-draper.iteye.com/blog/2333191
Mybatis 解析Mapper(class):http://donald-draper.iteye.com/blog/2333293
//全局文件的解析的方法在XMLConfigBuilder中,今天来具体看一下如何解析environments
//XMLConfigBuilder
//解析transactionManager
先看configuration的构造,启动有JDBC,POOLED类型的映射关系,这个在解析environment节点时,需要用到
从上可以看出JDBC,POOLED类型别名的映射关系如下:
JDBC,JdbcTransactionFactory
POOLED,PooledDataSourceFactory
//JdbcTransactionFactory
//TransactionFactory
现在来看一下jdbc事务
//Transaction
从上面可以看出jdbc对应的事务工厂为JdbcTransactionFactory,由JdbcTransactionFactory,根据数据源,事务级别以及自动提交属性来,创建JdbcTransaction,而JdbcTransaction的事务管理,是通过数据连接connection,而connection是从datasource获取,JdbcTransaction的事务管理,就是依靠相应的数据库driver,来管理,实际依赖于数据库。
//解析dataSource
// PooledDataSourceFactory
//UnpooledDataSourceFactory
//PooledDataSource
从上面可以看出解析datasource节点,就是解析器属性,并初始化datasource,
PooledDataSourceFactory继承UnpooledDataSourceFactory,改变的只是数据源类型,
PooledDataSourceFactory对应的数据源为PooledDataSource,而UnpooledDataSourceFactory对应的为,UnpooledDataSource;
我们再来看解析environment节点是,environment的构造
//Environment
再来看,Configuration设置environment
总结:
事务类型为jdbc对应的事务工厂为JdbcTransactionFactory,由JdbcTransactionFactory,根据数据源,事务级别以及自动提交属性来,创建JdbcTransaction,而JdbcTransaction的事务管理,是通过数据连接connection,而connection是从datasource获取,JdbcTransaction的事务管理,就是依靠相应的数据库driver,来管理,实际依赖于数据库;解析datasource节点,就是解析器属性,并初始化datasource,PooledDataSourceFactory继承UnpooledDataSourceFactory,改变的只是数据源类型,PooledDataSourceFactory对应的数据源为PooledDataSource,而UnpooledDataSourceFactory对应的为,UnpooledDataSource。
Mybatis加载解析Mapper(xml)文件第一讲:http://donald-draper.iteye.com/blog/2333125
Mybatis加载解析Mapper(xml)文件第二讲:http://donald-draper.iteye.com/blog/2333191
Mybatis 解析Mapper(class):http://donald-draper.iteye.com/blog/2333293
//全局文件的解析的方法在XMLConfigBuilder中,今天来具体看一下如何解析environments
//XMLConfigBuilder
private void parseConfiguration(XNode root) { try { propertiesElement(root.evalNode("properties")); typeAliasesElement(root.evalNode("typeAliases")); pluginElement(root.evalNode("plugins")); objectFactoryElement(root.evalNode("objectFactory")); objectWrapperFactoryElement(root.evalNode("objectWrapperFactory")); settingsElement(root.evalNode("settings")); //解析environments environmentsElement(root.evalNode("environments")); databaseIdProviderElement(root.evalNode("databaseIdProvider")); typeHandlerElement(root.evalNode("typeHandlers")); mapperElement(root.evalNode("mappers")); } catch(Exception e) { throw new BuilderException((new StringBuilder()).append("Error parsing SQL Mapper Configuration. Cause: ").append(e).toString(), e); } } //解析environments private void environmentsElement(XNode context) throws Exception { if(context != null) { if(C == null) environment = context.getStringAttribute("default"); Iterator i$ = context.getChildren().iterator(); //遍历environments的child节点environment,并解析 do { if(!i$.hasNext()) break; XNode child = (XNode)i$.next(); String id = child.getStringAttribute("id"); //如果environment的id属性,与environments的default相同时,才解析 if(isSpecifiedEnvironment(id)) { //解析transactionManager TransactionFactory txFactory = transactionManagerElement(child.evalNode("transactionManager")); //解析dataSource DataSourceFactory dsFactory = dataSourceElement(child.evalNode("dataSource")); javax.sql.DataSource dataSource = dsFactory.getDataSource(); org.apache.ibatis.mapping.Environment.Builder environmentBuilder = (new org.apache.ibatis.mapping.Environment.Builder(id)).transactionFactory(txFactory).dataSource(dataSource); configuration.setEnvironment(environmentBuilder.build()); } } while(true); } }
//解析transactionManager
先看configuration的构造,启动有JDBC,POOLED类型的映射关系,这个在解析environment节点时,需要用到
typeAliasRegistry.registerAlias("JDBC", org/apache/ibatis/transaction/jdbc/JdbcTransactionFactory); typeAliasRegistry.registerAlias("POOLED", org/apache/ibatis/datasource/pooled/PooledDataSourceFactory);
public Configuration() { safeRowBoundsEnabled = false; safeResultHandlerEnabled = true; mapUnderscoreToCamelCase = false; aggressiveLazyLoading = true; multipleResultSetsEnabled = true; useGeneratedKeys = false;//允许JDBC支持生成的键 useColumnLabel = true; cacheEnabled = true;//全局的映射器启用或禁用缓存 callSettersOnNulls = false; localCacheScope = LocalCacheScope.SESSION;//本地一级缓存作用域 jdbcTypeForNull = JdbcType.OTHER; lazyLoadTriggerMethods = new HashSet(Arrays.asList(new String[] { "equals", "clone", "hashCode", "toString" })); defaultExecutorType = ExecutorType.SIMPLE; autoMappingBehavior = AutoMappingBehavior.PARTIAL; variables = new Properties(); objectFactory = new DefaultObjectFactory();//默认ObjectFactory objectWrapperFactory = new DefaultObjectWrapperFactory();//默认DefaultObjectWrapperFactory mapperRegistry = new MapperRegistry(this); lazyLoadingEnabled = false; interceptorChain = new InterceptorChain();//插件链 typeHandlerRegistry = new TypeHandlerRegistry();//类型处理注册器 typeAliasRegistry = new TypeAliasRegistry();//类型别名注册器 languageRegistry = new LanguageDriverRegistry(); //mappedStatements Map mappedStatements = new StrictMap("Mapped Statements collection"); //mappedStatements,method,二级缓存 caches = new StrictMap("Caches collection"); //MapperInterface 方法返回结果类型Map resultMaps = new StrictMap("Result Maps collection"); //MapperInterface 方法参数类型Map parameterMaps = new StrictMap("Parameter Maps collection"); //主键生成器Map keyGenerators = new StrictMap("Key Generators collection"); loadedResources = new HashSet(); //Mapper.xml 中statement片段 sqlFragments = new StrictMap("XML fragments parsed from previous mappers"); //未解析处理的statements incompleteStatements = new LinkedList(); //未解析处理的CacheRefs incompleteCacheRefs = new LinkedList(); //未解析处理的ResultMaps incompleteResultMaps = new LinkedList(); //未解析处理的Methods incompleteMethods = new LinkedList(); cacheRefMap = new HashMap(); typeAliasRegistry.registerAlias("JDBC", org/apache/ibatis/transaction/jdbc/JdbcTransactionFactory); typeAliasRegistry.registerAlias("MANAGED", org/apache/ibatis/transaction/managed/ManagedTransactionFactory); typeAliasRegistry.registerAlias("JNDI", org/apache/ibatis/datasource/jndi/JndiDataSourceFactory); typeAliasRegistry.registerAlias("POOLED", org/apache/ibatis/datasource/pooled/PooledDataSourceFactory); typeAliasRegistry.registerAlias("UNPOOLED", org/apache/ibatis/datasource/unpooled/UnpooledDataSourceFactory); typeAliasRegistry.registerAlias("PERPETUAL", org/apache/ibatis/cache/impl/PerpetualCache); typeAliasRegistry.registerAlias("FIFO", org/apache/ibatis/cache/decorators/FifoCache); typeAliasRegistry.registerAlias("LRU", org/apache/ibatis/cache/decorators/LruCache); typeAliasRegistry.registerAlias("SOFT", org/apache/ibatis/cache/decorators/SoftCache); typeAliasRegistry.registerAlias("WEAK", org/apache/ibatis/cache/decorators/WeakCache); typeAliasRegistry.registerAlias("VENDOR", org/apache/ibatis/mapping/VendorDatabaseIdProvider); typeAliasRegistry.registerAlias("XML", org/apache/ibatis/scripting/xmltags/XMLLanguageDriver); typeAliasRegistry.registerAlias("RAW", org/apache/ibatis/scripting/defaults/RawLanguageDriver); typeAliasRegistry.registerAlias("SLF4J", org/apache/ibatis/logging/slf4j/Slf4jImpl); typeAliasRegistry.registerAlias("COMMONS_LOGGING", org/apache/ibatis/logging/commons/JakartaCommonsLoggingImpl); typeAliasRegistry.registerAlias("LOG4J", org/apache/ibatis/logging/log4j/Log4jImpl); typeAliasRegistry.registerAlias("JDK_LOGGING", org/apache/ibatis/logging/jdk14/Jdk14LoggingImpl); typeAliasRegistry.registerAlias("STDOUT_LOGGING", org/apache/ibatis/logging/stdout/StdOutImpl); typeAliasRegistry.registerAlias("NO_LOGGING", org/apache/ibatis/logging/nologging/NoLoggingImpl); typeAliasRegistry.registerAlias("CGLIB", org/apache/ibatis/executor/loader/CglibProxyFactory); typeAliasRegistry.registerAlias("JAVASSIST", org/apache/ibatis/executor/loader/JavassistProxyFactory); languageRegistry.setDefaultDriverClass(org/apache/ibatis/scripting/xmltags/XMLLanguageDriver); languageRegistry.register(org/apache/ibatis/scripting/defaults/RawLanguageDriver); }
从上可以看出JDBC,POOLED类型别名的映射关系如下:
JDBC,JdbcTransactionFactory
POOLED,PooledDataSourceFactory
<environments default="development"> <environment id="development"> <transactionManager type="JDBC" /> <dataSource type="POOLED"> <property name="driver" value="${driver}" /> <property name="url" value="${url}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> </dataSource> </environment> </environments>
private TransactionFactory transactionManagerElement(XNode context) throws Exception { if(context != null) { String type = context.getStringAttribute("type"); Properties props = context.getChildrenAsProperties(); //从类型解决器中,获取type对应的类型的实例,从上面的配置来看 //实际为JdbcTransactionFactory TransactionFactory factory = (TransactionFactory)resolveClass(type).newInstance(); //设置JdbcTransactionFactory属性 factory.setProperties(props); return factory; } else { throw new BuilderException("Environment declaration requires a TransactionFactory."); } }
//JdbcTransactionFactory
public class JdbcTransactionFactory implements TransactionFactory { public void setProperties(Properties properties) { } //根据数据连接新建事务 public Transaction newTransaction(Connection conn) { return new JdbcTransaction(conn); } //根据数据源和事务级别和是否自动提交,新建事务 public Transaction newTransaction(DataSource ds, TransactionIsolationLevel level, boolean autoCommit) { return new JdbcTransaction(ds, level, autoCommit); } }
//TransactionFactory
public interface TransactionFactory { public abstract void setProperties(Properties properties); public abstract Transaction newTransaction(Connection connection); public abstract Transaction newTransaction(DataSource datasource, TransactionIsolationLevel transactionisolationlevel, boolean flag); }
现在来看一下jdbc事务
public class JdbcTransaction implements Transaction { private static final Log log = LogFactory.getLog(org/apache/ibatis/transaction/jdbc/JdbcTransaction); protected Connection connection;//数据库连接 protected DataSource dataSource;//数据源 protected TransactionIsolationLevel level;//事务级别 protected boolean autoCommmit;//自动提交属性 public JdbcTransaction(DataSource ds, TransactionIsolationLevel desiredLevel, boolean desiredAutoCommit) { dataSource = ds; level = desiredLevel; autoCommmit = desiredAutoCommit; } public JdbcTransaction(Connection connection) { this.connection = connection; } public Connection getConnection() throws SQLException { if(connection == null) openConnection(); return connection; } public void commit() throws SQLException { if(connection != null && !connection.getAutoCommit()) { if(log.isDebugEnabled()) log.debug((new StringBuilder()).append("Committing JDBC Connection [").append(connection).append("]").toString()); connection.commit(); } } public void rollback() throws SQLException { if(connection != null && !connection.getAutoCommit()) { if(log.isDebugEnabled()) log.debug((new StringBuilder()).append("Rolling back JDBC Connection [").append(connection).append("]").toString()); connection.rollback(); } } public void close() throws SQLException { if(connection != null) { resetAutoCommit(); if(log.isDebugEnabled()) log.debug((new StringBuilder()).append("Closing JDBC Connection [").append(connection).append("]").toString()); connection.close(); } } protected void setDesiredAutoCommit(boolean desiredAutoCommit) { try { if(connection.getAutoCommit() != desiredAutoCommit) { if(log.isDebugEnabled()) log.debug((new StringBuilder()).append("Setting autocommit to ").append(desiredAutoCommit).append(" on JDBC Connection [").append(connection).append("]").toString()); connection.setAutoCommit(desiredAutoCommit); } } catch(SQLException e) { throw new TransactionException((new StringBuilder()).append("Error configuring AutoCommit. Your driver may not support getAutoCommit() or setAutoCommit(). Requested setting: ").append(desiredAutoCommit).append(". Cause: ").append(e).toString(), e); } } protected void resetAutoCommit() { try { if(!connection.getAutoCommit()) { if(log.isDebugEnabled()) log.debug((new StringBuilder()).append("Resetting autocommit to true on JDBC Connection [").append(connection).append("]").toString()); connection.setAutoCommit(true); } } catch(SQLException e) { log.debug((new StringBuilder()).append("Error resetting autocommit to true before closing the connection. Cause: ").append(e).toString()); } } //获取connection protected void openConnection() throws SQLException { if(log.isDebugEnabled()) log.debug("Openning JDBC Connection"); connection = dataSource.getConnection(); if(level != null) connection.setTransactionIsolation(level.getLevel()); setDesiredAutoCommit(autoCommmit); } }
//Transaction
public interface Transaction { public abstract Connection getConnection() throws SQLException; public abstract void commit() throws SQLException; public abstract void rollback() throws SQLException; public abstract void close() throws SQLException; }
从上面可以看出jdbc对应的事务工厂为JdbcTransactionFactory,由JdbcTransactionFactory,根据数据源,事务级别以及自动提交属性来,创建JdbcTransaction,而JdbcTransaction的事务管理,是通过数据连接connection,而connection是从datasource获取,JdbcTransaction的事务管理,就是依靠相应的数据库driver,来管理,实际依赖于数据库。
//解析dataSource
private DataSourceFactory dataSourceElement(XNode context) throws Exception { if(context != null) { //获取数据源的类型,和属性 String type = context.getStringAttribute("type"); Properties props = context.getChildrenAsProperties(); //根据type从configuration的类型处理器,获取具体的DataSourceFactory //从上文,我们看一看到type为POOLED,对应的是PooledDataSourceFactory DataSourceFactory factory = (DataSourceFactory)resolveClass(type).newInstance(); factory.setProperties(props); return factory; } else { throw new BuilderException("Environment declaration requires a DataSourceFactory."); } }
// PooledDataSourceFactory
public class PooledDataSourceFactory extends UnpooledDataSourceFactory { public PooledDataSourceFactory() { dataSource = new PooledDataSource(); } }
//UnpooledDataSourceFactory
public class UnpooledDataSourceFactory implements DataSourceFactory { private static final String DRIVER_PROPERTY_PREFIX = "driver."; private static final int DRIVER_PROPERTY_PREFIX_LENGTH = "driver.".length(); protected DataSource dataSource; public UnpooledDataSourceFactory() { dataSource = new UnpooledDataSource(); } public void setProperties(Properties properties) { Properties driverProperties = new Properties(); //获取dataSource的对象描述 MetaObject metaDataSource = SystemMetaObject.forObject(dataSource); //获取dataSource的所有属性,并设置 for(Iterator i$ = properties.keySet().iterator(); i$.hasNext();) { Object key = i$.next(); String propertyName = (String)key; if(propertyName.startsWith("driver.")) { String value = properties.getProperty(propertyName); driverProperties.setProperty(propertyName.substring(DRIVER_PROPERTY_PREFIX_LENGTH), value); } else if(metaDataSource.hasSetter(propertyName)) { String value = (String)properties.get(propertyName); Object convertedValue = convertValue(metaDataSource, propertyName, value); metaDataSource.setValue(propertyName, convertedValue); } else { throw new DataSourceException((new StringBuilder()).append("Unknown DataSource property: ").append(propertyName).toString()); } } //设置metaDataSource的driverProperties属性 if(driverProperties.size() > 0) metaDataSource.setValue("driverProperties", driverProperties); } public DataSource getDataSource() { return dataSource; } //将value转化为metaDataSource的对应setValue的参数类型 private Object convertValue(MetaObject metaDataSource, String propertyName, String value) { Object convertedValue = value; Class targetType = metaDataSource.getSetterType(propertyName); if(targetType == java/lang/Integer || targetType == Integer.TYPE) convertedValue = Integer.valueOf(value); else if(targetType == java/lang/Long || targetType == Long.TYPE) convertedValue = Long.valueOf(value); else if(targetType == java/lang/Boolean || targetType == Boolean.TYPE) convertedValue = Boolean.valueOf(value); return convertedValue; } }
//PooledDataSource
public class PooledDataSource implements DataSource { private final PoolState state; private final UnpooledDataSource dataSource; protected int poolMaximumActiveConnections; protected int poolMaximumIdleConnections; protected int poolMaximumCheckoutTime; protected int poolTimeToWait; protected String poolPingQuery; protected boolean poolPingEnabled; protected int poolPingConnectionsNotUsedFor; private int expectedConnectionTypeCode; }
从上面可以看出解析datasource节点,就是解析器属性,并初始化datasource,
PooledDataSourceFactory继承UnpooledDataSourceFactory,改变的只是数据源类型,
PooledDataSourceFactory对应的数据源为PooledDataSource,而UnpooledDataSourceFactory对应的为,UnpooledDataSource;
我们再来看解析environment节点是,environment的构造
org.apache.ibatis.mapping.Environment.Builder environmentBuilder = (new org.apache.ibatis.mapping.Environment.Builder(id)).transactionFactory(txFactory).dataSource(dataSource);
//Environment
public final class Environment { private final String id; private final TransactionFactory transactionFactory; private final DataSource dataSource; public static class Builder { public Environment build() { return new Environment(id, transactionFactory, dataSource); } private String id; private TransactionFactory transactionFactory; private DataSource dataSource; public Builder(String id) { this.id = id; } } }
再来看,Configuration设置environment
public void setEnvironment(Environment environment) { this.environment = environment; }
总结:
事务类型为jdbc对应的事务工厂为JdbcTransactionFactory,由JdbcTransactionFactory,根据数据源,事务级别以及自动提交属性来,创建JdbcTransaction,而JdbcTransaction的事务管理,是通过数据连接connection,而connection是从datasource获取,JdbcTransaction的事务管理,就是依靠相应的数据库driver,来管理,实际依赖于数据库;解析datasource节点,就是解析器属性,并初始化datasource,PooledDataSourceFactory继承UnpooledDataSourceFactory,改变的只是数据源类型,PooledDataSourceFactory对应的数据源为PooledDataSource,而UnpooledDataSourceFactory对应的为,UnpooledDataSource。
发表评论
-
Mybatis缓存实现
2016-12-07 10:36 978SqlSessionFactory初始化:http://don ... -
DefaultSqlSession第三讲-事务提交,回滚,关闭SqlSession,清除缓存
2016-11-20 11:07 5695上面两篇讲过query和update及flushStateme ... -
DefaultSqlSession第二讲-更新,刷新Statement
2016-11-20 11:06 627上一篇文章中,我们讲到DefaultSqlSession的查询 ... -
DefaultSqlSession第一讲query解析
2016-11-20 11:06 1619上一篇文章:我们说过DefaultSqlSession,Def ... -
Mybatis的SqlSession解析
2016-11-20 11:02 2542在前文中,Mybatis使用教程中,有下面一段代码: Sql ... -
Mybatis的Reflector解析
2016-11-18 12:53 2157Mybatis的MetaObject解析:http://don ... -
Mybatis的MetaObject解析
2016-11-18 11:40 9575SqlSessionFactory初始化:http://don ... -
mybatis 动态标签语句的解析(BoundSql)
2016-10-30 09:48 5752SqlSessionFactory初始化:http://don ... -
Mybatis 解析Mapper(class)
2016-10-26 11:44 3342SqlSessionFactory初始化:http://don ... -
Mybatis加载解析Mapper(xml)文件第二讲
2016-10-25 21:30 4780SqlSessionFactory初始化:http://don ... -
Mybatis加载解析Mapper(xml)文件第一讲
2016-10-25 16:51 6172SqlSessionFactory初始化:http://don ... -
SqlSessionFactory初始化
2016-10-20 15:38 2453mybatis 使用教程:http://donald-drap ... -
mybatis 使用教程
2016-10-14 09:03 906Myeclispe下mybatis generator的使 ... -
Spring+Mybatis多数据源的实现
2016-09-21 18:15 3093浅谈Spring事务隔离级别:http://www.cnblo ... -
mybaitis CDATA 防止字符被解析
2016-08-17 18:45 722在使用mybatis 时我们sql是写在xml 映射文件中,如 ... -
Myeclispe下mybatis generator的使用
2016-07-05 18:05 1373准备:下载附件包解压到myeclispe的dropins文件夹 ...
相关推荐
### MyBatis基础知识与应用详解 #### 一、MyBatis概述 MyBatis是一个优秀的持久层框架,它简化了Java应用程序与关系型数据库交互的复杂性。原名为iBatis,起初作为Apache的一个开源项目,后于2010年迁移到Google ...
### MyBatis通用Mapper知识点详解 #### 一、MyBatis通用Mapper简介 MyBatis通用Mapper是一种基于MyBatis框架的扩展插件,它能够为开发者提供一系列方便的CRUD(创建、读取、更新、删除)操作方法,极大地简化了...
### MyBatis 3.2.6 相关知识点详解 #### 一、MyBatis 概述 **MyBatis** 是一款优秀的持久层框架,它支持普通的 SQL 查询、存储过程以及高级映射功能。该框架的主要目标是简化 JDBC 代码的编写,并消除手动设置参数...
本篇文章将详细解析MyBatis的“Hello World”实例,帮助初学者快速入门。 【描述】"初始的mybatis的helloworld文档" MyBatis的“Hello World”教程是学习其基本概念和配置的绝佳起点。通过这个简单的例子,我们...
### Mybatis学习手册知识点解析 #### 一、MyBatis简介 - **定义与功能**:MyBatis是一个优秀的持久层框架,支持SQL查询、存储过程及高级映射功能。其核心价值在于几乎消除了所有JDBC代码和参数手工设置以及结果集...
### MyBatis用户手册知识点详解 #### 一、MyBatis概述 - **定义与特点:** - **定义:** MyBatis是一款优秀的持久层框架,它支持使用普通的SQL查询、存储过程以及高级映射功能。通过使用简单的XML或注解进行配置...
#### 二、MyBatis核心概念解析 **1. SqlSessionFactoryBuilder:** - **功能:**创建SqlSessionFactory的工厂类。 - **使用场景:**在应用程序启动时通过配置文件或者直接指定配置的方式初始化。 **2. ...
《Spring Boot集成MyBatis详解》 在Java开发领域,Spring Boot以其简洁的配置和快速的启动特性,已经成为构建微服务应用的首选框架。而MyBatis作为一款强大的持久层框架,深受开发者喜爱,它提供了灵活的SQL映射...
### MyBatis详细示例操作知识点解析 #### 一、MyBatis简介及特性 - **定义**:MyBatis是一种优秀的对象关系映射(Object Relational Mapping, ORM)框架,支持基本SQL查询、存储过程及高级映射等功能。通过减少...
MyBatis Properties 及别名定义实例详解 MyBatis 是一个基于 Java 的持久层框架,它提供了一个简单的方式来访问数据库。MyBatis 的配置文件是 mybatis-configuration.xml,这个文件中包含了数据库的连接信息、...
本文将深入解析MyBatis项目的配置文件实例,帮助开发者更好地理解和使用这个强大的持久层框架。 配置文件通常以`mybatis-config.xml`为名,它是MyBatis的核心配置文件,包含了环境设置、映射器配置等关键信息。以下...
通过理解MyBatis的工作原理,可以自己动手实现一个简化版的MyBatis框架,涉及到XML解析、SqlSessionFactoryBuilder、SqlSessionFactory、SqlSession等核心组件的构建。 **6. 在Web中应用MyBatis(使用MVC架构)** ...
### MyBatis配置详解 #### 一、简介 在学习如何配置MyBatis的过程中,我们需要了解两个关键的配置文件:`Mapper`配置文件与`config`配置文件。这两个文件是MyBatis框架运行的核心,它们定义了数据访问层(Data ...
### MyBatis 核心配置文件详解 #### 文件命名与结构 在 MyBatis 的学习过程中,一个重要的起点就是理解其核心配置文件的作用与结构。按照惯例,此文件通常命名为 `mybatis-config.xml`,它负责管理全局配置,如...
### MyBatis面试题知识点详解 #### 1. MyBatis简介 - **定义**: MyBatis是一款优秀的持久层框架,支持定制化的SQL、存储过程以及高级映射。 - **功能**: 避免了大量的JDBC代码和手动设置参数及获取结果集的操作,...
配置文件详解 Mybatis的核心配置文件是`mybatis-config.xml`,其中包含了数据库连接信息以及其他全局配置。以下是该文件的基本结构: ```xml <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//...
#### 二、MyBatis核心配置文件解析 MyBatis的核心配置文件主要由以下几部分组成: 1. **`<configuration>`**:根元素,包含了其他所有元素。 2. **`<settings>`**:用于改变MyBatis运行时的行为,例如开启二级缓存...
【mybatis半自动化解耦详解】 在Java的持久层框架中,Mybatis因其灵活和高效的特点,成为许多开发者的选择。本文将深入探讨Mybatis如何实现半自动化解耦,并通过具体的代码示例解析其CRUD(Create, Read, Update, ...
**SpringMVC与MyBatis整合精简实例详解** 在Java Web开发中,SpringMVC作为主流的MVC框架,负责处理HTTP请求并转发到相应的控制器,而MyBatis作为一个轻量级的持久层框架,简化了SQL操作。将两者结合使用,可以构建...