莫问天涯路几重,轻衫侧帽且从容。这篇文章主要讲述Mybatis MetaObject和ObjectWrapper设计概念相关的知识,希望能为你提供帮助。
ObjectWrapper
文章图片
该类的作用是对象的包装,对对象属性的操作,其行为有
文章图片
BaseWrapper
文章图片
具备了MetaObject,对象包装的公共父类,主要处理集合类型
文章图片
BeanWrapper具备了储存对象的Object和MetaClass
@Override public Object get(PropertyTokenizer prop) { if (prop.getIndex() != null) { // 使用MetaObject逐级实例化集合对象 Object collection = resolveCollection(prop, object); // 使用MetaObject获得Value return getCollectionValue(prop, collection); } else { return getBeanProperty(prop, object); } }
MetaObject
private final Object originalObject; private final ObjectWrapper objectWrapper; private final ObjectFactory objectFactory; private final ObjectWrapperFactory objectWrapperFactory; private final ReflectorFactory reflectorFactory; private MetaObject(Object object, ObjectFactory objectFactory, ObjectWrapperFactory objectWrapperFactory, ReflectorFactory reflectorFactory) { this.originalObject = object; this.objectFactory = objectFactory; this.objectWrapperFactory = objectWrapperFactory; this.reflectorFactory = reflectorFactory; // 根据originalObject的类型实例化具体的ObjectMapper,将MetaObject自己注入进去,委派模式 if (object instanceof ObjectWrapper) { this.objectWrapper = (ObjectWrapper) object; } else if (objectWrapperFactory.hasWrapperFor(object)) { this.objectWrapper = objectWrapperFactory.getWrapperFor(this, object); } else if (object instanceof Map) { this.objectWrapper = new MapWrapper(this, (Map) object); } else if (object instanceof Collection) { this.objectWrapper = new CollectionWrapper(this, (Collection) object); } else { this.objectWrapper = new BeanWrapper(this, object); } }
获得初始对象的属性值通过ObjectWrapper并可能委派给MetaObject来获得。
【Mybatis MetaObject和ObjectWrapper设计概念】
推荐阅读
- 轻量ORM-SqlRepoEx (十四)最佳实践之Dapper
- FunctorApplicative 和 Monad x
- c#开发移动APP-Xamarin入门
- Android studio 不能创建Activity等文件
- adb.Android手机可以通过adb执行按键操作
- 第七篇-列表式App(ListActivity及ListView)
- 第三篇-以LinearLayout进行Android界面设计
- Android------------UI的控件学习内容
- TensorFlow教程入门介绍详细解释