Package io.mybatis.activerecord.spring
Class MapperProvider<T,I extends Serializable,M extends BaseMapper<T,I>>
- java.lang.Object
-
- io.mybatis.activerecord.spring.MapperProvider<T,I,M>
-
- Type Parameters:
T- 实体类类型I- 主键类型M- 实体对应的 Mapper
- All Implemented Interfaces:
EventListener,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
public class MapperProvider<T,I extends Serializable,M extends BaseMapper<T,I>> extends Object implements org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
根据实体类提供对应的 Mapper 接口实例- Author:
- liuzh
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.springframework.context.ApplicationContextapplicationContextSpring 上下文protected Map<Class<?>,BaseMapper<T,I>>modelMapper缓存默认注入的实例protected org.mybatis.spring.SqlSessionTemplatesqlSessionTemplate必须使用线程安全的SqlSessionTemplate
-
Constructor Summary
Constructors Constructor Description MapperProvider(org.mybatis.spring.SqlSessionTemplate sqlSessionTemplate)构造方法,必须使用线程安全的SqlSessionTemplate
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMapper(Class<?> type, Object mapper)添加 Mapper 接口和实例(可选)MbaseMapper(Class<T> modelClass)获取实体类对应的 Mapper 接口static <T,I extends Serializable,M extends BaseMapper<T,I>>
MapperProvider<T,I,M>getDefaultInstance()获取默认实例static <T,I extends Serializable,M extends BaseMapper<T,I>>
MapperProvider<T,I,M>getInstance(String instanceName)获取指定的实例protected voidinitMapper()voidonApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)voidregisterAsDefault()将当前实例设置为默认实例voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)
-
-
-
Field Detail
-
applicationContext
protected static org.springframework.context.ApplicationContext applicationContext
Spring 上下文
-
modelMapper
protected Map<Class<?>,BaseMapper<T,I extends Serializable>> modelMapper
缓存默认注入的实例
-
sqlSessionTemplate
protected org.mybatis.spring.SqlSessionTemplate sqlSessionTemplate
必须使用线程安全的SqlSessionTemplate
-
-
Method Detail
-
getDefaultInstance
public static <T,I extends Serializable,M extends BaseMapper<T,I>> MapperProvider<T,I,M> getDefaultInstance()
获取默认实例- Returns:
- 默认实例
-
getInstance
public static <T,I extends Serializable,M extends BaseMapper<T,I>> MapperProvider<T,I,M> getInstance(String instanceName)
获取指定的实例- Returns:
- 默认实例
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
onApplicationEvent
public void onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)
- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<T>
-
initMapper
protected void initMapper()
-
addMapper
public void addMapper(Class<?> type, Object mapper)
添加 Mapper 接口和实例(可选)- Parameters:
type- Mapper 接口类mapper- Mapper 实例
-
baseMapper
public M baseMapper(Class<T> modelClass)
获取实体类对应的 Mapper 接口- Parameters:
modelClass- 实体类- Returns:
- Mapper 接口
-
registerAsDefault
public void registerAsDefault()
将当前实例设置为默认实例
-
-