The abstract project uses the MyBatis to manipulate the database itself before using the framework, but it is only in the stage of being used, so it makes a lot of mistakes. Recently in the finishing project and many things, have seen that familiar and unfamiliar old friends. So I want to completely understand the old friend in the end how many things I do not know. Let me also after less fan error ... mybatis config sqlsessionfactory profile database
directory [-] 1:properties property file 2:settings configuration 3:typealiases type alias (entity type alias); 4:typehandlers type handle 5 Objectfactory object Factory 6 PLU Gins plug-in 7 environments Environment 8 Mappers Mapper
In the grooming project is found the configuration of the DAO layer about the database
<configuration>
<settings>
<setting name= "cacheenabled" value= "false"/>
</settings>
<typeAliases>
<package name= "Com.desksoft.oceanus.goods.dataobject"/>
<package name= "Com.desksoft.oceanus.goods.vo"/>
</typeAliases>
</configuration>
Only a few lines of configuration are available because the Sping-mybatis implementation of the project is implemented by spring.
Think about it and know the result, using spring, of course, is the spring configuration data source datasource. Then Mybatis-config.xml content reduction that is also normal.
Why? Then you need to review what the file does. Why does the MyBatis framework require this configuration file?
Any persistence layer framework is an operational database that reads and writes database information so it's bound to have a database.
Sessionfactory used by habernate
Mybatis's Sqlsessionfactory
And so on are persistent layer Framework operations database Yes session factory
MyBatis applications are mostly using sqlsessionfactory instances, and a sqlsessionfactory instance can be obtained through Sqlsessionfactorybuilder.
The sqlsessionfactorybuilder can be obtained from an instance of a Mybatis-config.xml configuration file or a pre-defined configuration class.
The Mybatis-config.xml configuration file is a link to the configuration database, so here's a look at the tags in the file.
The MyBatis configuration file includes the following tags:
Configuration
|---Properties
|---settings
|---typealiases
|---typehandlers
|---objectfactory
|---plugins
|---environments
|---|---environment
|---|---|---transactionmanager
|---|---|__ dataSource
|__ mappers 1:properties Properties File
Properties refers to the × in Java;. Properties
Configure the properties of the resource to specify ×. The path to the properties,
The property's name and value are then configured under the Properties tab, and the corresponding attribute values in the properties file can be replaced. Variable using ${****} 2:settings configuration
There are a number of major configurations and descriptions of the settings configuration as follows:
Property name |
Simple description |
Setting the value |
Default value |
|
Cacheenabled |
Global on/Off settings for all caches under this profile |
true | False |
True |
|
Lazyloadingenabled |
Global Settings lazy Loading. If set to ' false ', all associated will be initialized to load. |
true | False |
True |
|
Aggressivelazyloading |
When set to ' true ', lazy-loaded objects may be loaded by any lazy property. Otherwise, each property is loaded on demand. |
true | False |
True |
|
Multipleresultsetsenabled |
Allow and disallow single statements to return multiple datasets |
true | False |
True |
|
Usecolumnlabel |
Use column labels instead of column names. Different drives have different practices. Refer to the drive documentation, or test with these two different options. |
true | False |
True |
|
Usegeneratedkeys |
Allows JDBC to generate a primary key. Drive support is required. If set to true, this setting enforces the generated primary key, and some drives are incompatible but can still be executed. |
true | False |
False |
|
Automappingbehavior |
Specifies whether MyBatis and how to automatically map the data table fields with the properties of the object. Partial will only automatically map simple, no nested results. Full will automatically map all the complex results. |
NONE, PARTIAL, Full |
PARTIAL |
|
Defaultexecutortype |
Configure and set actuators, simple actuators execute other statements. The reuse executor may reuse prepared statements statements, and batch executor can execute statements and batch updates repeatedly. |
Simple Reuse BATCH |
Simple |
|
Defaultstatementtimeout |
Set a time limit to determine how long the drive waits for the database to respond to timeouts |
Positive integers |
Not Set null) |
|
alias of type 3:typealiases (entity type alias);
Type aliases are abbreviations for Java types. is the short name of the Java object
It is only associated to the Map.xml configuration, and it is not necessary to write the full Java object name map.xml the alias is configured.
<typeAliases>
<typealias alias= "userentity" type= "com.fengyi.entity.UserEntity"/>
<typealias alias= "studententity" type= "com.fengyi.entity.StudentEntity"/>
<typealias alias= "classentity" type= "com.fengyi.entity.ClassEntity"/>
</typeAliases>
Alias property if not write default is the class name first letter lowercase
Basic types and special types of alias mapping relationships
Alias |
Types of mappings |
_byte |
Byte |
_long |
Long |
_short |
Short |
_int |
Int |
_integer |
Int |
_double |
Double |
_float |
Float |
_boolean |
Boolean |
String |
String |
Byte |
Byte |
Long |
Long |
Short |
Short |
Int |
Integer |
Integer |
Integer |
Double |
Double |
Float |
Float |
Boolean |
Boolean |
Date |
Date |
Decimal |
BigDecimal |
BigDecimal |
BigDecimal |
Object |
Object |
Map |
Map |
HashMap |
HashMap |
List |
List |
ArrayList |
ArrayList |
Collection |
Collection |
Iterator |
Iterator |
4:typehandlers Type handle
Whether MyBatis sets a parameter in a preprocessing statement or extracts a value from the result set, the type processor is used to convert the obtained value to the Java type in the appropriate way.
The following table describes the default type processor.
Type processor |
Java type |
JDBC Type |
Booleantypehandler |
Boolean,boolean |
Any of the compatible Boolean values |
Bytetypehandler |
Byte,byte |
Any compatible number or byte type |
Shorttypehandler |
Short,short |
Any compatible number or short integer |
Integertypehandler |
Integer,int |
Any compatible number and integral type |
Longtypehandler |
Long,long |
Any compatible number or long integer |
Floattypehandler |
Float,float |
Any compatible digital or single-precision floating-point type |
Doubletypehandler |
Double,double |
Any compatible digital or double-precision floating-point type |
Bigdecimaltypehandler |
BigDecimal |
Any compatible number or decimal decimal type |
Stringtypehandler |
String |
char and varchar types |
Clobtypehandler |
String |
CLOB and LongVarChar types |
Nstringtypehandler |
String |
nvarchar and nchar types |
Nclobtypehandler |
String |
NCLOB type |
Bytearraytypehandler |
Byte[] |
Any compatible byte stream type |
Blobtypehandler |
Byte[] |
Blob and LongVarBinary types |
Datetypehandler |
Date (Java.util) |
Timestamp type |
Dateonlytypehandler |
Date (java.util |