1. mybaits-config core profile label
Integrating Mybaits into Spring requires adding some configuration files. Its core configuration file is mybaits-config.xml.
1.1, configuration Label
The configurationtag is the parent of all tags and corresponds to the configuration class configuration for mybaits.
1.2, Properrties tag
Properrties is a label used to import a property file to add a database connection configuration. This label may not exist, but the database connection configuration of mybaits-config.xml requires hard coding. A corresponding property file allows you to configure configuration information in a property file.
<properties resource="db.properties"></properties>
1.3, typeAliases tag
An alias tag that specifies an alias for a single object so that in the Mybaits framework's xml file, all locations where the full path name of the object needs to be written can be aliased.
In addition to user-defined alias tags, Mybaits also defines aliases that are mapped in the TypeAliasRegistry class
<typeAliases> <typeAlias alias="user" type="com.my.li.bean.User"/> </typeAliases>
1.4, typeHandler tag
There are methods for converting database types to java data types in the TypeHandlerRegistry class. After downloading the source code, look again to see that all types of handlers inherit BaseTypeHandler for type conversion. If you want to do some special conversion, you need to write a custom handler, inherit BaseTypeHandler, override the conversion method, andAdd to the typeHandler tag.
<typeHandlers> <typeHandler handler="com.my.li.handler.MyTypeHandler"/> </typeHandlers>
Once the definition is complete, use the typeHandler after the required field to indicate the handler used.
<resultMap id="BaseResultMap" type="com.my.li.bean.User"> <id column="user_id" jdbcType="BIGINT" property="userId" /> <result column="user_name" jdbcType="VARCHAR" property="userName" typeHandler="com.my.li.handler.MyTypeHandler"/> <result column="user_age" jdbcType="INTEGER" property="userAge" /> <result column="user_sex" jdbcType="INTEGER" property="userSex" /> </resultMap>
1.5, objectFactory tag
There are four methods within the ObjectFactory interface, which Mybaits uses to create corresponding objects. It has a default implementation class, DefaultObjectFactory. If a developer wants to use some other actions when creating objects, he or she can customize a class by implementing the ObjectHandler or inheriting the DefaultObjectFactory and declare it in the ObjectHandler tag.
There are also property subtags under the objectHandler tag, which define some key-value pairs
<objectFactory type="com.my.li.factory.MyObjectFactory"> <property name="test" value="one"/> </objectFactory>
1.6, plugins tag
Plug-in tags, which can be used to extend Mybaits functionality, can only block critical methods in the four plug-ins. When defining multiple plug-ins, the execution order of the plug-ins is bottom-up.
<plugins> <plugin interceptor="com.my.li.interceptor.SQLInterceptor"> <property name="test" value="one"/> </plugin> <plugin interceptor="com.my.li.interceptor.PageInterceptor"/> </plugins>
1.7, Environment Label
Environment Label Environment Configuration is used to configure the database environment. Each environment label represents a data source, transactionManager is responsible for configuring transactions, datasource label represents a data source, POOLED represents a connection pool, and UNPOOLED represents a database connection configuration without a connection pool property.
<environments default="development"> <environment id="development"> <transactionManager type="JDBC"/> <dataSource type="POOLED"> <property name="driver" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </dataSource> </environment> </environments>
1.8, mappers tag
Specify the startup path file, you can specify
- Class Path Resource Reference
- Fully qualified resource locator
- Implement fully qualified class names for classes using mapper interfaces
- Register all mapper interface implementations within the package as mappers
<mappers> <mapper resource="BlogMapper.xml"/> <mapper resource="BlogMapperExt.xml"/> </mappers>
1.9, settings tag
1.9.1,cacheEnabled
Determining whether to turn on secondary caching in a project
1.9.2,localCacheScope
Level 1 Cache Scope
1.9.3,lazyLoadingEnabled
lazyLoadingEnabled = false, then delayed loading is disabled and all associated object data is cascaded
lazyLoadingEnabled = true, mybatis is loaded with hierarchical delay by default.
1.9.4,laggressiveLazyLoading
aggressiveLazyLoading = true, mybatis is loaded with hierarchical delay
aggressiveLazyLoading = false, mybatis loaded on demand.
1.9.5,lazyLoadTriggerMethods
Delayed Loading
1.9.6,defaultExecutorType
Executor type, SIMPLE common executor, REUSE reusable executor, BATCH batch operation data
1.9.7,logImpl
Log implementation
2. Mapper Mapping File Label
2.1,cache
Cache configuration for a given namespace
2.2,cache-ref
References to other namespace cache configurations
2.3,resultMap
Describes how to load objects from a database result set
2.4,sql
Reusable SQL statements that can be referenced by other statements
2.5,insert
Mapping Insert Statement
2.6,update
Mapping Update Statement
2.7,delete
Map Delete Statement
2.8,select
Mapping Lookup Statement