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
} }

©2019-2020 Toolsou All rights reserved,
use easyPOI Import Excel data Vue Transfer parameters and receiving of page Jump Digital rolling lottery program The difference between memory overflow and memory leak , Causes and Solutions vue monitor Treeselect Change of options Image format conversion TypeScript- Polymorphism JavaScript Medium Call and Applyk8s Entry to give up --k8s Key concepts How to build data security system ?