Mybatis中SqlMapConfig.xml配置文件

9.1. 配置内容
SqlMapConfig.xml 中配置的内容和顺序如下:
 
properties (属性)
settings (全局配置参数)
typeAliases (类型别名)
typeHandlers (类型处理器)
objectFactory (对象工厂)
plugins (插件)
environments (环境集合属性对象)
environment (环境子属性对象)
transactionManager (事务管理)
dataSource (数据源)
mappers (映射器)
9.2. properties (属性)
SqlMapConfig.xml 可以引用java 属性文件中的配置信息如下:

config 下定义db.properties 文件,如下所示:
Mybatis中SqlMapConfig.xml配置文件_第1张图片

db.properties配置文件内容如下:
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
SqlMapConfig.xml引用如下:



    
    
       
       
       
       
    

    
       
           
           
           
           
              
              
              
              
           
       
    
 
    
    
       
       
    

 
注意: MyBatis 将按照下面的顺序来加载属性:
u   properties 元素体内定义的属性首先被读取。
u   然后会读取properties 元素中resource url 加载的属性,它会覆盖已读取的同名属性。
1.2. typeAliases (类型别名)
1.2.1. mybatis 支持别名:
别名
映射的类型
_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
map
Map
1.2.2. 自定义别名:
SqlMapConfig.xml 中配置如下:



    
    
       
       
       
    
 
    
       
       
       
       
       
    
 
    
    
       
           
           
           
           
              
              
              
              
           
       
    
 
    
    
       
       
    

 
mapper.xml 配置文件中,就可以使用设置的别名了
别名大小写不敏感

1.3. mappers (映射器)
Mapper 配置的几种方法:
1.3.1.
使用相对于类路径的资源(现在的使用方式)
如:
 
1.3.2.
使用mapper 接口类路径
如:
 
注意: 此种方法要求 mapper 接口名称和 mapper 映射文件名称相同,且放在同一个目录中
 
1.3.3.
注册指定包下的所有mapper 接口
如:
注意: 此种方法要求 mapper 接口名称和 mapper 映射文件名称相同,且放在同一个目录中
 

你可能感兴趣的:(MyBatis,mybatis,mappers)