Talk about your understanding of MyBatis

Talk about your understanding of MyBatis

(1) Mybatis is a semi-ORM (object-relational mapping) framework. It encapsulates JDBC internally. When developing, you only need to pay attention to the SQL statement itself, and you don’t need to spend the manager to handle complicated processes such as loading drivers, creating connections, and creating statements. Developers can directly write native SQL, and can control SQL performance with high flexibility.
(2) MyBatis can use XML or annotations to configure and map native information, and map java objects to records in the database, avoiding almost all JDBC codes and manually setting parameters and obtaining result sets.
(3) Configure various Statements to be executed through XML files or annotations, and map the dynamic parameters of SQL in Java objects and Statements into final SQL statements. Finally, the MyBatis framework executes SQL and maps the results to Java objects and return.

What are the advantages and disadvantages of MyBatis

Advantages:
(1) Programming based on SQL statements is quite flexible and will not have any impact on the existing design of applications or databases. SQL is written in XML, which decouples SQL from program codes and facilitates unified management; provides XML tags, Supports writing dynamic SQL statements and can be reused.
(2) Compared with JDBC, it reduces the amount of code, eliminates a lot of redundant code of JDBC, and does not need to manually switch the connection.
(3) Very good database compatibility (because Mybatis uses JDBC to link the database, so as long as the JDBC-supported database MyBatis supports it) (
4) Provides mapping tags and supports ORM field relationship mapping between objects and databases.

What is the difference between #{} and ${} in Mybatis?

#{} is precompiled processing, ${} is string replacement
(1) When Mybatis processes #{}, it will replace #{} in SQL with? Number, call the set method of PreparedStatement to assign value, using #{} can effectively prevent SQL injection and improve system security.
(2) When MyBatis processes ${}, it replaces {} with the value of the variable.

Guess you like

Origin blog.csdn.net/weixin_49131718/article/details/131647241