In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
What is 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.
Structure flow corresponding to MyBatis source code
SqlMapConfig.xml, as the global configuration file of mybatis, configures the running environment of mybatis and other information. The mapper.xml file, the sql mapping file, is configured with sql statements to manipulate the database, and this file needs to be loaded in SqlMapConfig.xml.
Mapper.xml
Select * from user_info where id = # {id}
two。 SqlSessionFactory (that is, session factory) is constructed from configuration information such as the mybatis environment.
String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream (resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder () .build (inputStream)
3. The sqlSession is created by the session factory, and the operation of the database needs to be done through sqlSession.
SqlSession session = sqlSessionFactory.openSession ()
The bottom layer of 4.mybatis defines the Executor executor interface to operate the database. The Executor interface has two implementations, one is the basic executor and the other is the cache executor.
5.MappedStatement is also an underlying encapsulation object of mybatis, which wraps mybatis configuration information and sql mapping information. A sql in the mapper.xml file corresponds to a MappedStatement object, and the id of sql is the id of MappedStatement.
6.MappedStatement defines the input parameters of sql execution, including HashMap, basic types, and pojo,Executor maps the input java object to sql before performing sql through MappedStatement. The input parameter mapping is to set parameters for preparedStatement in JDBC programming.
7.MappedStatement defines the output result of sql execution, including HashMap, basic type, and pojo,Executor maps the output result to java object after performing sql through MappedStatement. The mapping process of output result is equivalent to the parsing process of the result in JDBC programming.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.