sqlMapConfig.xml
 
SqlMapConfig.xml中配置的内容和顺序如下:
 
properties(属性)
settings(全局配置参数)
typeAliases(类型别名)
typeHandlers(类型处理器)
objectFactory(对象工厂)
plugins(插件)
environments(环境集合属性对象)
environment(环境子属性对象)
transactionManager(事务管理)
dataSource(数据源)
mappers(映射器)
 
1.1 properties属性定义
 可以把一些通用的属性值配置在属性文件中,加载到mybatis运行环境内。
比如:创建db.properties配置数据库连接参数。
注意:在xml文件中,&->&,但是在properties文件中,&->
MyBatis-sqlMapConfig.xml
MyBatis-sqlMapConfig.xml
MyBatis-sqlMapConfig.xml
MyBatis-sqlMapConfig.xml
 
 
注意: MyBatis 将按照下面的顺序来加载属性:
properties 元素体内定义的属性首先被读取。
然后会读取properties 元素中resourceurl 加载的属性,它会覆盖已读取的同名属性。
最后读取parameterType传递的属性,它会覆盖已读取的同名属性。
 
建议使用properties,不要在properties中定义属性,只引用定义的properties文件中属性,并且properties文件中定义的key要有一些特殊的规则。
 
1.2 settings全局参数配置
mybatis运行时可以调整一些全局参数(相当于软件的运行参数),参考:mybatis-settings.xlsx
根据使用需求进行参数配置。
注意:小心配置,配置参数会影响mybatis的执行。
 
ibatis的全局配置参数中包括很多的性能参数(最大线程数,最大待时间。。。),通过调整这些性能参数使ibatis达到高性能的运行,mybatis没有这些性能参数,由mybatis自动调节。
 
1.3 typeAliases(常用)
 
可以将parameterTyperesultType中指定的类型 通过别名引用。
 
1.3.1 mybaits提供了很多别名
别名 映射的类型
_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
 
1.3.2 自定义别名
MyBatis-sqlMapConfig.xml
MyBatis-sqlMapConfig.xml
 
 
1.3.3 使用别名
parameterTyperesultType中使用别名:
MyBatis-sqlMapConfig.xml
MyBatis-sqlMapConfig.xml
 
1.3.4 typeHandlers
 
类型处理器将java类型和jdbc类型进行映射。
 
mybatis默认提供很多类型处理器,一般情况下够用了。
 
1.3.5 mappers
MyBatis-sqlMapConfig.xml
MyBatis-sqlMapConfig.xml

相关文章:

  • 2021-10-12
  • 2022-12-23
  • 2021-06-18
  • 2021-08-20
  • 2021-06-07
  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
  • 2021-10-17
相关资源
相似解决方案