javaconfig配置的sessionFactory在DAO层怎么注入进来

2024-11-28 13:39:19
推荐回答(1个)
回答1:

public SqlSession open() {
Reader reader;
try {
reader = Resources.getResourceAsReader("SQLMapConfig.xml");
SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder()
.build(reader);
sqlSession = sessionFactory.openSession();
} catch (IOException e) {
System.out.println("SQLMapConfig.xml读取失败");
e.printStackTrace();
}
return sqlSession;
}
这个是mybatis的 当然其他的也一样的道理