MyBatis初始化基本步驟

    private InputStream in = null;
    private SqlSessionFactory factory = null;
    private SqlSession sqlSession = null;
    private IAccountDao iAccountDao = null;

    public void init() throws Exception{
        in = Resources.getResourceAsStream("SqlMapConfig.xml");
        factory = new SqlSessionFactoryBuilder().build(in);
        sqlSession = factory.openSession();
        iAccountDao = sqlSession.getMapper(IAccountDao.class);
    }

    public void destory() throws Exception{
        sqlSession.commit();
        sqlSession.close();
        in.close();
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章