mybatis-databaseIdProvider多数据库支持

原文链接: https://www.cnblogs.com/happyflyingpig/p/7689289.html

        SELECT NOW() FROM dual
    
    

 四、在configuration.xml中添加映射器


    

 五、jdbc.properties文件

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/mybatis-learn?characterEncoding=utf8
jdbc.username=root
jdbc.password=tiger

#jdbc.driver=oracle.jdbc.driver.OracleDriver
#jdbc.url=jdbc:oracle:thin:@localhost:1521:mybatis
#jdbc.username=mybatis
#jdbc.password=mybatis

maxActive= 50

 六、测试

import com.yihaomen.mybatis.dao.DatabaseIdProviderMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import user.BaseTest;

public class DatabaseIdProviderTest extends BaseTest{

    public static void main(String[] args) {
        SqlSessionFactory factory = getSession();
        SqlSession session = factory.openSession();
        DatabaseIdProviderMapper mapper = session.getMapper(DatabaseIdProviderMapper.class);
        System.out.println(mapper.selectTime());
    }
}
  • 结果说明 
    如果当前启用的是oracle则执行databaseId=”oracle”的语句,如果mysql值执行databaseId=”mysql”的语句

 https://gitee.com/huayicompany/springmvc-mybatis

 参考文献:

 [1] 杨开振 著,《深入浅出MyBatis技术原理与实战》, 电子工业出版社,2016.09

 [2]火柴盒zhang博客,http://blog.csdn.net/likewindy/article/details/51396576

 

你可能感兴趣的:(mybatis)