MyBatis-Add, delete, modify and check (CRUD) operation of a single table

      Before learning the operation of adding, deleting, modifying and checking a single table of MyBatis, I should familiarize myself with the MyBatis framework again. Only when I am familiar with it can I use it well and develop flexibly.

        MyBatis Advantages:

        1), easy to learn

       mybatis itself is small and simple. Without any third-party dependencies, the simplest installation only requires two jar files + configuration of several sql mapping files. It is easy to learn and use. Through the documentation and source code, you can fully grasp its design ideas and implementation.

        2), flexible

       mybatis does not impose any impact on the existing design of the application or database. SQL is written in xml, which is convenient for unified management and optimization. Basically everything we can do without using a data access framework is possible through sql, maybe more.

        3), decoupling sql and program code

       By providing the DAL layer, the business logic and data access logic are separated, making the system design clearer, easier to maintain, and easier to unit test. The separation of sql and code improves maintainability. For developers, the core SQL still needs to be optimized by itself: SQL and Java coding are separated, the functional boundaries are clear, one focuses on business, and the other focuses on data.

        4) Provide mapping labels to support the mapping of orm field relationships between objects and databases. 

        5), provide object relationship mapping label, support the maintenance of object relationship.

        6), provide xml tags, support writing dynamic sql.

        MyBatis Disadvantages: 

        1) The workload of writing SQL statements is very large, especially when there are many fields and many associated tables.  

        2), SQL statements depend on the database, resulting in poor database portability, and the database cannot be replaced. 

        3) The framework is still relatively simple, and the functions are still missing. Although the data binding code is simplified, the entire underlying database query actually has to be written by itself, the workload is relatively large, and it is not easy to adapt to rapid database modification.

MyBatis and JDBC comparison:

SQL is sandwiched in Java code blocks, and the high degree of coupling leads to internal damage of hard coding, maintenance is not easy, and there are changes in SQL in actual development requirements, and frequent modifications are common.

MyBatis compared with Hibernate and JPA:

It is not easy for Hibernate to deal with long and complex SQL, and it is not easy to do special optimization for the SQL that is automatically generated internally. Based on the fully automatic framework of full mapping, it is difficult to partially map POJOs with a large number of fields. Degraded database performance.

        MyBatis vs iBatis:

        MyBatis is an upgraded version of iBatis. There are many similarities in usage, but MyBatis has made important improvements.

        1), Mybatis implements interface binding, which is more convenient to use.

In ibatis2.x, we need to specify which xml mapping file corresponds to the DAO implementation class, and Mybatis implements the binding of the DAO interface and the xml mapping file, and automatically generates the specific implementation of the interface for us, which makes it easier to use. and convenient.

        2) The object relational mapping is improved, and the efficiency is higher.

        3), MyBatis uses powerful OGNL-based expressions to eliminate other elements.

    

    Here's some dry goods. MyBatis's single-table addition, deletion, modification, and query operations have begun to perform. Please get on the bus. ForFuture

I believe that after reading my  MyBatis usage steps , you  will have a good understanding of the following.

        1. Write the Mapper mapping file User.xml  


       2. Test CRUD




The above is a simple use of MyBatis to add, delete, modify and check. View the previous article: Steps to use MyBatis

If you need to learn MyBatis completely, you can click to download [ Complete MyBatis Study Notes ]
After writing Spring+MyBatis+Spring MVC and other articles, I have compiled a set of [ Complete Practical Documents ] , click to download if necessary

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325585926&siteId=291194637