1. Create a sqlsession through SqlSessionFactory, then obtain the session object from Sqlsession, and then execute the sql statement encapsulated by MapperStatement through the executor in the session.
@Test public void findAll() throws IOException { //1. Read the configuration file InputStream in = (""); //2. Create the builder object of SqlSessionFactory SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder(); //3. Create factory object using builder SqlSessionFactory SqlSessionFactory factory = (in); //4. Use SqlSessionFactory to produce SqlSession objects SqlSession session = (); List<User> users = ("findAll"); /* //5. Use SqlSession to create a proxy object for the dao interface (jdk dynamic proxy used in the interface binding principle) UserDao userDao = (); //6. Use proxy object to execute query all methods List<User> users = (); */ for (User user : users) { (user); } //7. Release resources (); (); }
2. Classification of Executor
- SimpleExecutor: The default Executor, a new Statement will be created during each SQL execution, inheriting
- BaseExecutor
- CachingExecutor: Executor that can cache data, executor used for secondary cache
- BatchExecutor: Executor for batch processing
- ReuseExecutor: Statement that the same SQL will take
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.