Case Getting Started

  / ** 
     * Getting Case 
     * / 
    public  static  void main (String [] args) throws IOException {
         // 1, reads the configuration file 
        InputStream in = Resources.getResourceAsStream ( "the mybatis-config.xml" );
         // 2, create sqlSessionFactory plant 
        the SqlSessionFactoryBuilder Builder = new new the SqlSessionFactoryBuilder (); 
        a sqlSessionFactory factory = builder.build (in);
         // . 3, using the object factory SQLSESSION 
        SqlSession SQLSESSION = factory.openSession ();
         // . 4, created using SqlSession interface proxy object Dao
        Mapper = sqlSession.getMapper DemoMapper (DemoMapper. Class );
         // . 5, using the proxy object execution method 
        List <Demo> demoList = mapper.getDemoList ();
         for (Demo Demo: demoList) { 
            System.out.println (demo.getId () + "" + demo.getName ()); 
        } 
        // . 6, release resources 
        sqlSession.close (); 
        in.close (); 

    }

 

Guess you like

Origin www.cnblogs.com/bichen-01/p/11718603.html