The difference between Mybatis and Ibatis:
1. Mybatis implements interface binding, making it more convenient to use <br />In ibatis2.x, we need to specify which xml mapping file corresponds to in the DAO implementation class.
Mybatis implements the binding of the DAO interface and the xml mapping file, and automatically generates the specific implementation of the interface for us, making it easier to use and more convenient.
This can be said to be the most important improvement of Mybatis.
Notice:
Although Mybatis supports the use of annotation configuration directly in the interface to simplify configuration,
However, it is strongly recommended to still use the XML configuration method. After all, the configuration method of annotation is limited and the code is too invasive. Only by using the XML configuration method can the advantages of Mybatis be reflected
2. Improvement of object relationship mapping is more efficient <br />I believe that many friends who are using ibatis2.x do not realize relationship mapping between objects through ibatis' xml mapping file. In fact, there is no need to do that, because ibatis2.x uses "necked query" to realize the relationship between objects through the direct assembly of query statements, and its effect is the same as encapsulation in DAO or Service.
However, this method has "N+1 query problem".
In summary, the N+1 query problem can be caused like this:
? You execute a separate SQL statement to get the result list (that is +1).
? For each record returned, you execute a query statement to load the details for each loading (that is, N).
This problem can cause hundreds of SQL statements to be executed. This is usually not expected.
In Mybatis, in addition to being compatible with the "necked query" method in ibatis2.x, it also provides a direct "necked result" method, which is equivalent to automatically encapsulating the queryed dto object into the required object through a sentence SQL.
For specific implementation methods, please refer to the Mybatis official user manual by yourself, and do not describe them here.
However, in fact, the benefits brought by this improvement are very limited. Because this method does not work when using paging, or the result set of nested objects is not allowed to be paging. This has been clearly restricted in the Mybatis framework (34 lines in org.apache.ibatis.executor.resultset.NestedResultSetHandler), and there are many cases where paging is required in actual projects...
If you think about it carefully, one-to-many mapping cannot be paging through configuration files, because the number of records queried at this time does not equal the size of the actual return object, but I don’t understand why one-to-one mapping is not allowed. Maybe it is because one-to-one is a one-to-many special case, and when designing the framework, it is not considered or difficult to deal with this special case.
3. MyBatis uses powerful OGNL-based expressions to eliminate other elements <br />People who are familiar with struts2 should not be unfamiliar with OGNL expressions.
MyBatis uses OGNL expressions to simplify the complexity of configuration files and is simpler to use.
Maybe it's more concerned
Mybatis implements interface binding, making it more convenient to use.
iBatis/MyBatis 3 provides a new feature: annotation.