Why is MyBatis so "dick"? These MyBatis secrets, hang on the interviewer every minute

Why look at the source code

  1. Improve technical skills Java foundation
  2. In-depth mastery of the technical framework
  3. Quickly locate online problems
  4. Interview must ask
  5. Technical pursuit

What is the principle

  1. The principle of fixed focus: grasp the main line (grab a core process to analyze, don't look at the source code aimlessly)
  2. Macro principle: From the perspective of God, first context and then branches (don’t try to figure out every line of code)

What are the methods

  1. Will use it first, understand the design ideas and functional architecture of the framework
  2. Grasp the main line, try to see the code statically
  3. Write comments & draw flowcharts in source code
  4. Integration summary

What are the skills

  1. Breakpoints (observe the call stack, use conditional breakpoints, expressions)
  2. Reverse (Find Usages)
  3. Find the specific implementation of AoP AopProxyFactory according to the interface method
  4. Guess the class name and method name (such as doGetBean, doCreateBean)
  5. See console log

What mentality should be used to read the source code

  1. Overcome the fear of source code
  2. Calm down and read the source code

Disadvantages of traditional JDBC:

  1. The bottom layer of jdbc does not use connection pools, and operating databases requires frequent creation and association links. Consume a lot of resources

  2. Write native jdbc code in java, once we want to modify sql, java needs to be compiled as a whole, which is not conducive to system maintenance

  3. If you use PreparedStatement to pre-compile, set the variable to 123 numbers, which is not conducive to maintenance

  4. Returning the result result set also needs to be hard-coded.

mybatis core concept

Configuration 、 SqlSessionFactory 、 Session 、 Executor 、 MappedStatement 、StatementHandler、ResultSetHandler

name significance
Configuration Manage mysql-config.xml global configuration relationship class
SqlSessionFactory Session management factory interface
Session SqlSession is an interface for users (programmers). SqlSession provides many methods of operating the database
Executor The executor is an interface (basic executor, cache executor). Function: SqlSession uses the executor to operate the database
MappedStatement The role of the underlying package object: storage package for the operation database, including sql statements, input and output parameters
StatementHandler Specific operation database-related handler interface
ResultSetHandler Handler interface for specific operation database return results

Insert picture description here

Source code process:

Insert picture description here

Source code compilation and download

https://github.com/mybatis/mybatis-3
https://github.com/mybatis/parent (dependency)

Insert picture description here

The idea can be imported directly or downloaded as a zip package (recommended).
Insert picture description here

Mybatis source code hits the parent project. You need to compile the parent project before compiling mybatis, as follows

Solve the parent dependency problem:

During the build process, it will appear that the parent module mybatis-parent that is dependent on the pom.xml cannot be found.
We need to clone the paren project into the local directory: git clone https://github.com/mybatis/parent.git, and then first Enter the parent project and perform mvn clean install. Download the package that the parent project depends on and ensure that the parent project is compiled. This step will not cause problems. In the compiled output information, we will see the parent project 版本号, as shown in the figure:
Insert picture description here

The version tag where the parent depends on the pom.xml file is as follows.
Next, modify the place where the parent depends on the pom.xml file of the mybatis project:

org.mybatis
mybatis-parent
28-SNAPSHOT
…/parent/pom.xml

tells us that some plug-ins do not specify the corresponding version number, for the stability of the project Sexual considerations need to specify the version number of the plug-in used, and give the appropriate version number, as shown in the red box. We only need to find the corresponding plug-in in the pom.xml file of the mybatisg project and add the $NUM tag, where $NUM represents the specific version number. At this point, we can execute the mvn clean install command to build the mybatis project successfully.

At last

If you have a different understanding of this article or have opinions, please comment in the comment area. In addition, I have built a group, as a learning platform, if you have any questions, you can ask questions in the group, and you can also receive a compiled large factory In the face, click here to enter the group, the secret code CSDN, the
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
above information has been sorted out, you can click here to get it for free, the secret code CSDN

Guess you like

Origin blog.csdn.net/yueyunyin/article/details/109386860