Mybatis之:SqlSessionFactory、SqlSession

复制代码
public class CountryMapperTest {
    private static SqlSessionFactory sqlSessionFactory;

    @BeforeClass
    public static void init() {
        try {
            Reader reader = Resources.getResourceAsReader("mybatis-config.xml");
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
            reader.close();
        } catch (IOException ignore) {
            ignore.printStackTrace();
        }
    }

    @Test
    public void testSelectAll() {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        try {
            List<CountryEntity> countryList = sqlSession.selectList("TestList");
            printCountryList(countryList);
        } finally {
            //不要忘记关闭 sqlSession
            sqlSession.close();
        }
    }
}
复制代码

 

posted @   cuiqq  阅读(372)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示