Class MapperProvider<T,​I extends Serializable,​M extends BaseMapper<T,​I>>

  • 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 Detail

      • applicationContext

        protected static org.springframework.context.ApplicationContext applicationContext
        Spring 上下文
      • sqlSessionTemplate

        protected org.mybatis.spring.SqlSessionTemplate sqlSessionTemplate
        必须使用线程安全的 SqlSessionTemplate
    • Constructor Detail

      • MapperProvider

        public MapperProvider​(org.mybatis.spring.SqlSessionTemplate sqlSessionTemplate)
        构造方法,必须使用线程安全的 SqlSessionTemplate
        Parameters:
        sqlSessionTemplate - 线程安全的 SqlSessionTemplate
    • Method Detail

      • getDefaultInstance

        public static <T,​I extends Serializable,​M extends BaseMapper<T,​I>> MapperProvider<T,​I,​M> getDefaultInstance()
        获取默认实例
        Returns:
        默认实例
      • setApplicationContext

        public void setApplicationContext​(org.springframework.context.ApplicationContext applicationContext)
                                   throws org.springframework.beans.BeansException
        Specified by:
        setApplicationContext in interface org.springframework.context.ApplicationContextAware
        Throws:
        org.springframework.beans.BeansException
      • onApplicationEvent

        public void onApplicationEvent​(org.springframework.context.event.ContextRefreshedEvent event)
        Specified by:
        onApplicationEvent in interface org.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()
        将当前实例设置为默认实例