创建SqlSessionFactory
读取配置文件
/**
* Class.getResource(String path)
* 1、path不以’/'开头时,默认是从此类所在的包下取资源;
* 2、path 以’/'开头时,则是从ClassPath根下获取;
*/
System.out.println(" App.class.getResource(\"\") =="+ App.class.getResource("") );
System.out.println(" App.class.getResource(\"/\") =="+ App.class.getResource("/") );
/**
* Class.getClassLoader().getResource(String path)
* 1、path不能以’/'开头时;以/开头返回null
* 2、不以/开头的path是从ClassPath根下获取
*/
System.out.println(" App.class.getClassLoader().getResource(\"\") =="+ App.class.getClassLoader().getResource("") );
System.out.println(" App.class.getClassLoader().getResource(\"/\") =="+ App.class.getClassLoader().getResource("/") );
//打印结果
//App.class.getResource("") //==file:/D:/ideaProjects/mybatis/demo01/target/classes/yyq/mybatis/
//App.class.getResource("/") ==file:/D:/ideaProjects/mybatis/demo01/target/classes/
//App.class.getClassLoader().getResource("") //==file:/D:/ideaProjects/mybatis/demo01/target/classes/
//App.class.getClassLoader().getResource("/") ==null