1. 程式人生 > >mybatis測試類的連結規範1.0

mybatis測試類的連結規範1.0

  public static void main(String[] args) throws Exception {
    		//獲取xml檔案的路徑
    		String resource = "config/SqlMapConfig.xml";
    		//配置路徑
    		InputStream inputStream = Resources.getResourceAsStream(resource);
    		
    		//建立SqlSessionFactory
    		SqlSessionFactory sqlFactory = 
    				new SqlSessionFactoryBuilder().build(inputStream);
    		//建立SqlSession
    		SqlSession sqlSession = sqlFactory.openSession();
    		
    		/*
    		 * 你想做的操作
    		 * */
    		 user user1=sqlSession.selectOne("user.getUserById",1);
    		 system.print.out(user);
    		
    		sqlSession.close();
    	}