In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Starting from this blog post, we will learn about Mybatis and hope that you will put forward some valuable suggestions.
What is Mybatis?
MyBatis was originally an open source project of apache, iBatis, which was moved from apache software foundation to google code in 2010 and renamed MyBatis. The word iBATIS, which comes from the combination of "internet" and "abatis", is a persistence layer framework based on Java. The persistence layer framework provided by iBATIS includes SQL Maps and Data Access Objects (DAO).
MyBatis was originally an open source project of apache, iBatis, which was moved from apache software foundation to google code in 2010 and renamed MyBatis. The word iBATIS, which comes from the combination of "internet" and "abatis", is a persistence layer framework based on Java. The persistence layer framework provided by iBATIS includes SQL Maps and Data Access Objects (DAO).
[java] view plain copy print?
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 extracting result sets. MyBatis uses simple XML or annotations to configure and map primitives, mapping interfaces and Java's POJOs (Plain Old Java Objects, ordinary Java objects) to records in the database.
MyBatis is an updated version of iBatis, and there are many similarities in usage, but MyBatis has made important improvements. For example:
1. Mybatis implements interface binding, which is more convenient to use.
In ibatis2.x, we need to specify which xml mapping file corresponds to in the implementation class of DAO, and Mybatis implements the binding of DAO interface and xml mapping file, which automatically generates the specific implementation of the interface for us, which becomes more convenient and convenient to use.
2. The improvement of object-relational mapping makes it more efficient.
3. MyBatis uses powerful OGNL-based expressions to eliminate other elements.
I won't say any more about the difference between IBatis and MyBatis, and friends who are interested can study it.
The framework of MyBatis
When you see the frame diagram of Mybatis, you can clearly see the overall core object of Mybatis. I prefer to use my own diagram to express the whole execution process of Mybatis. As shown in the following figure:
Detailed explanation of the principle:
The MyBatis application creates the SqlSessionFactory,SqlSessionFactory from the XML configuration file according to the configuration, and the configuration comes from two places, one is the configuration file, the other is the annotation of the Java code, and gets a SqlSession. SqlSession contains all the methods needed to execute sql. You can run the mapped sql statement directly through the SqlSession instance to complete the addition, deletion, modification, query and transaction submission of data, and close SqlSession after use.
Advantages and disadvantages of MyBatis:
1. Simple and easy to learn
Mybatis itself is small and simple. Without any third-party dependence, the simplest installation is as long as two jar files + configuration several sql mapping files are easy to learn and use. Through documentation and source code, you can fully grasp its design ideas and implementation.
2. Flexibility
Mybatis does not impose any impact on the existing design of the application or database. Sql is written in xml for unified management and optimization. With sql, you can basically do everything we can do without using the data access framework, or more.
3. Uncouple sql and program code.
By providing DAL layer, the business logic and data access logic are separated, which makes the design of the system clearer, easier to maintain and easier to unit test. The separation of sql and code improves maintainability.
4. Provide mapping label to support orm field relation mapping between object and database.
5. Provide object-relational mapping tags to support object-relational construction and maintenance.
6. Provide xml tags to support writing dynamic sql.
Disadvantages:
1. It takes a lot of work to write SQL statements, especially when there are many fields and associated tables.
2. The SQL statement depends on the database, which leads to the poor portability of the database and can not replace the database.
3, the framework is still relatively simple, the function is still missing, although the data binding code is simplified, but the entire underlying database query actually has to be written on its own, the workload is also relatively large, and it is not easy to adapt to rapid database modification.
4. The second-tier cache mechanism is not good.
Summary
The advantage of mybatis is also the disadvantage of mybatis. Because mybatis is easy to use, the bottleneck of data reliability and integrity depends more on the programmer's level of use of sql. Sql is written in xml, although it facilitates modification, optimization and unified browsing, it is very low readability, debugging is also very difficult, but also very limited.
Mybatis is not as powerful as hibernate, but the biggest advantage of mybatis is that it is simple, compact and easy to use, making it easy to browse and modify sql statements.
Source code: × × / technology
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.