类 MapperFactoryBean<T>

  • 所有已实现的接口:
    org.springframework.beans.factory.FactoryBean<T>, org.springframework.beans.factory.InitializingBean

    public class MapperFactoryBean<T>
    extends org.mybatis.spring.support.SqlSessionDaoSupport
    implements org.springframework.beans.factory.FactoryBean<T>
    BeanFactory that enables injection of MyBatis mapper interfaces. It can be set up with a SqlSessionFactory or a pre-configured SqlSessionTemplate.

    Sample configuration:

     
     <bean id="baseMapper" class="org.mybatis.spring.mapper.MapperFactoryBean" abstract="true" lazy-init="true">
     <property name="sqlSessionFactory" ref="sqlSessionFactory" />
     </bean>
     <p>
     <bean id="oneMapper" parent="baseMapper">
     <property name="mapperInterface" value="my.package.MyMapperInterface" />
     </bean>
     <p>
     <bean id="anotherMapper" parent="baseMapper">
     <property name="mapperInterface" value="my.package.MyAnotherMapperInterface" />
     </bean>
     
     

    Note that this factory can only inject interfaces, not concrete classes.

    作者:
    Eduardo Macarron, liuzh
    另请参阅:
    SqlSessionTemplate
    • 构造器详细资料

      • MapperFactoryBean

        public MapperFactoryBean()
      • MapperFactoryBean

        public MapperFactoryBean​(Class<T> mapperInterface)
    • 方法详细资料

      • checkDaoConfig

        protected void checkDaoConfig()
        覆盖:
        checkDaoConfig 在类中 org.mybatis.spring.support.SqlSessionDaoSupport
      • getMapperInterface

        public Class<T> getMapperInterface()
        Return the mapper interface of the MyBatis mapper
        返回:
        class of the interface
      • setMapperInterface

        public void setMapperInterface​(Class<T> mapperInterface)
        Sets the mapper interface of the MyBatis mapper
        参数:
        mapperInterface - class of the interface
      • getObject

        public T getObject()
                    throws Exception
        指定者:
        getObject 在接口中 org.springframework.beans.factory.FactoryBean<T>
        抛出:
        Exception
      • getObjectType

        public Class<T> getObjectType()
        指定者:
        getObjectType 在接口中 org.springframework.beans.factory.FactoryBean<T>
      • isAddToConfig

        public boolean isAddToConfig()
        Return the flag for addition into MyBatis config.
        返回:
        true if the mapper will be added to MyBatis in the case it is not already registered.
      • setAddToConfig

        public void setAddToConfig​(boolean addToConfig)
        If addToConfig is false the mapper will not be added to MyBatis. This means it must have been included in mybatis-config.xml.

        If it is true, the mapper will be added to MyBatis in the case it is not already registered.

        By default addToCofig is true.

        参数:
        addToConfig -
      • setMapperHelper

        public void setMapperHelper​(tk.mybatis.mapper.mapperhelper.MapperHelper mapperHelper)
        设置通用 Mapper 配置
        参数:
        mapperHelper -
      • isSingleton

        public boolean isSingleton()
        指定者:
        isSingleton 在接口中 org.springframework.beans.factory.FactoryBean<T>