Integrate Mybatis

Mybatis replaced the previous hibernate, selected some of the advantages of hibernate, but cut off the one-to-many and many-to-one mapping features. According to the introduction of the official documentation:
quote
MyBatis is an excellent persistence layer framework that supports custom 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 for configuration and native Map to map interfaces and Java POJOs (Plain Old Java Objects, ordinary Java objects) into records in the database.

I haven't used lazy loading in the startSpring project for the time being. During the initial integration process, I called the startmentId myself in daoimp, but then I found that when the namespace of mapper.xml is mapped to the same dao interface class, dao will be automatically instantiated bean, so modify the namespace, delete daoImp, use an Interface basedao, and let the dao of ordinary classes inherit the interface and become a super interface, so as to avoid repeatedly writing the interface.
In the process of constructing dynamic SQL, because it is difficult to avoid the duplication of fields between tables, the select of assication is used for further query in resultMap, and the query condition is to use include, which also solves the problem of duplication of field names. . The query conditions will involve most of the fields, but most of the delete and update conditions will be updated and deleted according to the key ID. At the same time, the query will be paginated and sorted, but the delete update will not, so queryConditions and deleteConditions are separated.
For new and updated operations, the incoming parameters are set to map or list, mainly for batch update and batch addition, and to accommodate some field update operations, such as where $key=#{value} is used for conditions. Regarding the parameters, if the int type is passed in, even if you write
parameterType="java.util.Map"
It will not affect the value, however, if you pass in int but write the following code
<if test="id != null">and memberid=#{memberid,javeType=INTEGER}</if>
There will be an error in the judgment process, showing that there is no memberid in the integer, which is also something I didn't think clearly.
。<foreach collection="list" item="item" index="index" separator=",">
is an important part of the use of bulk operations.
github: http://github.com/leechedan/startSpring/mybatis

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326925820&siteId=291194637