* Need to master compiler knowledge
* Compiler is eclipse As an example
Commissioning preparations ( step :Window -> Show View -》...):
□ Open debug breakpoint Breakpoint:
□ Turn on variable monitoring :
It depends on the internal details of a method , Press f5, Get into
Jump to a certain position quickly 【 Make a breakpoint at the target location 】, Then press f8
Details of the observation method ( Execute the process ), Step by step , Press f6
Remove all breakpoints ( The compiler is eclipse)
□ Pay attention to whether the execution position of the start tag is correct
f5 Enter by debugging 【
If the entry is irrelevant , Press f7 return , Press again f5 Enter once
】
give an example :
User user = mapper.get(1L); // Make a breakpoint here to enter , Will enter first Long class , Because the order of execution is (1L) Execute first , So after entering it first , Re execution get Method
Press ctr and As debugged f5 The difference between :
□ ctr: Is to enter “ The selected code ( class 、 Interface 、 Method )” The location of the definition of 【 The emphasis isDefinition of code
】
□ f5: It is to execute the current code in the order of execution , Get into 、 Execute its internal 【 The emphasis isExecution of code
】Press ctr With the mouse , You can know the next step of the code ( Press ctr Details to pay attention to :ctr The default entry is the definition of the selected code , Not an implementation process , After entering, I found that I didn't see any helpful code , return Return press and hold ctr, Selective implementation ( If there are multiple implementations ,
I don't know which one to choose , It can be debugged f5 Get into
), Press the mouse again to enter .Restart debugging details :
(1) Close the last debugging
(2) Click on Before commissioning , Keep the... In front of the breakpoint at the start position √, Before other breakpoints √ Remove first ( Start debugging before √ Come back )After entering a method, learn the details of the method , Want to go back and then proceed , Press f7 return 【
Back to press f7
】
Generally, after in-depth understanding of a module , You can press return , return ... Then move on to the next module
* The idea of reading source code
1、 Focus on understanding the execution logic ( The execution process can be carried out as control Enter a method or class , Understand the next step
after , The cursor returns to the current position 【 Shortcut keys are alt+←】)
2、 Look at the source code process to clarify ideas , Abnormally related (error、exception、throw), The details that make the code more robust can be ignored ; Stack related stack, The bottom layer can be ignored
3、 In the code , See the selection Branch , You can observe the value of the variable ( Judge the condition ) Know which branch to enter
4、 In the code , See incomprehensible code , You can go down first , Then understand by observing the value of the variable 【 It can also be understood in combination with the official website 】
5、 Read stream 、 load resources 、 Binding namespace 、 Parameter conversion is not the point
6、 Constructing constructors is not the point , The point is to see The construction process of the constructor
7、 Constructing parsers is not the point , The point is to see The parsing process of the parser
8、 When you create a subclass, you should pay attention to : What kind of subclasses ? When a subclass has an encapsulated parent or sibling , Note what type of parent or sibling class is encapsulated ?
* How to focus on reading source code ( With mybatis The source code of )
■ 1、 The process of reading the source code , Which one should I read , Which is the key point of reading ?
- Read the source code to build the source code of the session factory object , I learned that : Created a SqlSessoinFactory The session factory object is through the default SqlSessoinFactory Created , When creating, you need to pass in a configuration object 【 That is, when creating the session factory object, a configuration object is also created 】, thus , Study the creation process of configuration objects .
- Read the source code to build the source code of the session factory object , I learned that : Create a sqlSession The session object is through the default sqlSession, You need to pass in three parameters when creating , The key is to observe which ?
□ configuration Configuration object ( I learned about it when I read the source code of session factory object construction , Is not the point )
□ executor actuator ( a key , Because in return The session object was previously built executor actuator )
□ autoCommit ( Submit or not , Boolean value , Is not the point )
- Combine to understand logic , also return The hint of , Know that the key point of reading is list The process of
* Words to master when reading the source code
- map mapping mapper mapper
- factory factory
- build structure
- config To configure
- parse analysis parser Parser parsed Has been resolved parseConfiguration Parsing configuration
- interceptor Interceptor
- plugin “ install [ enhance ]”、 plug-in unit
- proxy agent
- prepared precompiled callable Stored
- statment Statement object preparedStatement Precompiled statement object callableStatement Stored statement object
- cursor cursor
- instantiate Instantiation instantiateStatement Instantiate the statement object
- handler processor typeHandler Type processor
- row That's ok