1.MyBatis How to implement custom plug-in ?

Implementation principle :

MyBatis Custom plug-in for MyBatis
Four objects (Executor,StatementHandler,ParamentHandler,ResultSetHandler) Intercept .

* Executor  : Intercept internal actuators , It is responsible for calling StatementHandler Operation database , And pass the result set ResultSetHandler
Automatic mapping , In addition, it also handles the operation of L2 cache .
* StatementHandler  : intercept SQL Processing of grammatical construction , It is MyBatis Direct and database execution SQL The object of the script , In addition, it has been implemented
MyBatis First level cache
* ParamenterHandler  : Processing of interception parameters .
* ResultSetHandler  : Processing of interception result set .
Key to implementation :

MyBatis Plug in to implement Interceptor Interface , Methods contained in the interface , as follows :
public interface Interceptor { Object intrceptor(Invocation invocation)
throws Throwable; Object plugin(Object target); void setProperties(Properties
properties); }
* setProperties() The method is to MyBatis When configuring plug-ins, you can configure custom related properties , Namely : Parameter configuration of interface implementation object .
* plugin()
Method is used by the plug-in to encapsulate the target object , With this method, we can return the target object itself , You can also return a proxy for it , You can decide whether to intercept or not , And then decide what kind of target object to return .
* interceptor()  Method is the method to be executed when intercepting .
Custom plug-in implementation example :
@Intercepts({ @Signature(type = Executor.class, method = "query", args = {
MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class }) })
public class TestInterceptor implements Interceptor { @Override public Object
intercept(Invocation invocation) throws Throwable { Object target =
invocation.getTarget();// Principal method Method method = invocation.getMethod();// Proxy method
Object[] args = invocation.getArgs();// Method parameters // do something...... Method to execute the code block before interception
Object result = invocation.proceed(); // do something...... Method intercepts and executes the code block return
result; } @Override public Object plugin(Object target) { // TODO
Auto-generated method stub return Plugin.wrap(target, this); } @Override public
void setProperties(Properties properties) { // TODO Auto-generated method stub
} }
 

Technology
©2019-2020 Toolsou All rights reserved,
Non preemptive static priority scheduling algorithm for operating system (C language )Go Language learning notes (GUI programming )XCTF Attack and defense world web Advanced practice _ 2_lottery What's the difference between computer major and training background ?python realization vlookup_ Dry goods I : Why python It's inside vlookup Bubble sort primary springboot2 Separation of front and rear platforms ,token Put in header Pit for verification Python Case conversion of letters ( Two methods )javascript event ( Detailed explanation of zero basis )Unity2019 UIElement note ( ten ) Simple exercise 2