广发证券程序化交易网页版接口,mybatis通过JDK的动态代理方式,在启动加载配置文件时,根据配置广发证券程序化交易网页版接口,mapper的xml去生成Dao的实现。
原理
再根据网上的一些知识点,讲一下原理:
总结:这个就是利用JDK的代理类实现的。
这里是用到了JDK的代理Proxy。newMapperProxy()可以取得实现interfaces的class的代理类的实例。
MapperMethod类会使用method方法的methodName和declaringInterface去取sqlMapxml取得对应的sql,也就是拿declaringInterface的类全名加上sql-id…
当执行interfaces中的方法的时候,会自动执行invoke()方法,其中publicObjectinvoke(Objectproxy,Methodmethod,Object[]args)中method参数就代表你要执行的方法.
sessiogetMapper()使用了代理,当调用一次此方法,都会产生一个代理class的instance,看看这个代理class的实现.
public class MapperProxy implements InvocationHandler {
...
public static T newMapperProxy(Class 广发证券程序化交易网页版接口,mapperInterface, SqlSession sqlSession) {
ClassLoader classLoader = 广发证券程序化交易网页版接口,mapperInterface.getClassLoader();
Class>[] interfaces = new Class[]{广发证券程序化交易网页版接口,mapperInterface};
MapperProxy proxy = new MapperProxy(sqlSession);
return (T) Proxy.newProxyInstance(classLoader, interfaces, proxy);
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (!OBJECT_METHODS.contains(method.getName())) {
final Class> declaringInterface = findDeclaringInterface(proxy, method);
final MapperMethod 广发证券程序化交易网页版接口,mapperMethod = new MapperMethod(declaringInterface, method, sqlSession);
final Object result = 广发证券程序化交易网页版接口,mapperMethod.execute(args);
if (result == null && method.getReturnType().isPrimitive()) {
throw new BindingException('Mapper method '' + method.getName() + '' (' + method.getDeclaringClass() + ') attempted to return null from a method with a primitive return type (' + method.getReturnType() + ').');
}
return result;
}
return null;
}
文章为作者独立观点,不代表股票交易接口观点