首页 > 其他 > 详细

MyBatis 配置文件

时间:2017-02-23 18:40:15      阅读:164      评论:0      收藏:0      [点我收藏+]

1、properties

  有三种配置方式:

  a、采用java属性文件配置[ ***.properties ],在mybatis-config.xml 中如下调用:

<properties resource="jdbc.properties"/>

  b、采用mybatis-config.xml 中 properties 属性进行配置,如下: 

<properties>
<property name="driver" value="com.mysql.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/db_name"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</properties>

 c、使用java代码load配置文件 ***.properties,然后通过参数将配置传入,如下:

SqlSessionFactory sqlSessionFactory1 = new SqlSessionFactoryBuilder().build(InputStream inputStream, Properties properties)
SqlSessionFactory sqlSessionFactory1 = new SqlSessionFactoryBuilder().build(Reader reader, Properties properties)
SqlSessionFactory sqlSessionFactory1 = new SqlSessionFactoryBuilder().build(InputStream inputStream, String environment, Properties properties)
SqlSessionFactory sqlSessionFactory1 = new SqlSessionFactoryBuilder().build(Reader reader,String nvironment,Properties properties)

  加载顺序:

  配置文件properties体内读取 -- 》 配置文件properties的 url/resource文件中读取 -- 》 参数传递的属性中读取

  优先级顺序:

  参数传递的属性中读取(优先级最高) -- 》 配置文件properties的url/resource文件中读取(次之) -- 》 配置文件properties体内读取(优先级最低)

  如果三个地方都有配置,高优先级覆盖低优先级的配置

 

2、

MyBatis 配置文件

原文:http://www.cnblogs.com/sxx-java/p/6434556.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!