Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the execution process of MyBatis?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how the MyBatis implementation process is, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Introduction to Mybatis

MyBatis is an excellent persistence layer framework that supports customized SQL, stored procedures, and advanced mapping. MyBatis avoids almost all JDBC code and manually setting parameters and getting result sets. MyBatis can use simple XML or annotations to configure and map native information, mapping interfaces and Java's POJOs (Plain Old Java Objects, ordinary Java objects) to records in the database.

Mybatis detailed execution process

Load the global configuration file through Resource

Import org.apache.ibatis.io.Resources;import org.apache.ibatis.session.SqlSession;import org.apache.ibatis.session.SqlSessionFactory;import org.apache.ibatis.session.SqlSessionFactoryBuilder;import java.io.IOException;import java.io.InputStream;public class MyBatisUtils {private static SqlSessionFactory sqlSessionFactory; static {String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream (resource); sqlSessionFactory = new SqlSessionFactoryBuilder () .build (inputStream) } catch (IOException e) {e.printStackTrace ()}} public static SqlSession getSqlSession () {return sqlSessionFactory.openSession ();}}

Second, instantiate sqlSessionFactoryBuilder constructor

Third, parse the file stream, environment and attributes through the XmlConfigBuilder class in build.

4. Store the configuration information in Configuration

Then instantiate the SqlSessionFactory implementation class DefaultSqlSessionFactory and enter the underlying implementation process at this time

6. Create a Transaction transaction object by TransactionFactory

7. Create an actuator Excutor to execute mapper

8. Create SqlSession interface implementation class DefaultSqlSession

SqlSession sqlSession = MybatisUtils.getSqlSession () UserMapper mapper = sqlSession.getMapper (UserMapper.class)

9. Realize CURD

Determine whether the execution is successful, and if not, roll back to the transaction submitter

11. Transaction submission

SqlSession.commit ()

12. Close

SqlSession.close (): thank you for reading this article carefully. I hope the article "what is the implementation process of MyBatis" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report