首页 > 数据库技术 > 详细

Mybatis之:SqlSessionFactory、SqlSession

时间:2019-07-08 15:38:59      阅读:121      评论:0      收藏:0      [点我收藏+]
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();
        }
    }
}

 

Mybatis之:SqlSessionFactory、SqlSession

原文:https://www.cnblogs.com/cuiqq/p/11151362.html

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