Integrated mybatis (c)

Configuration Mapper

xml way:

<! - creating a single packet mapper generates the specified automatic scanning the bean -> 
<the bean ID = "the RoleMapper" class = "org.mybatis.spring.mapper.MapperFactoryBean"> 
    <Property name = "mapperInterface" value = "com.example.dao.RoleMapper" /> 
    <Property name = "a SqlSessionFactory" REF = "a SqlSessionFactory"> </ Property> 
</ bean> 
    <-! create a plurality of mapper in the specified packet generation automatic scanning bean -> 
    <the bean class = "org.mybatis.spring.mapper.MapperScannerConfigurer"> 
        <Property name = "basePackage" value = "com.example.dao" /> 
        <Property name = "SqlSessionFactoryBeanName" value = "a SqlSessionFactory" / >
        <! - Specify dimension scanning only become so mapper Mapper interfaces to add @Repository ->
        <property name="annotationClass" value="org.springframework.stereotype.Repository" />
    </bean>


config class configuration:

/ ** 
     * through automated scanning, found MyBatis mapper Interface 
     * @return Mapper scanner
      * / 
    @Bean 
    public MapperScannerConfigurer initMapperScannerConfigurer () { 
        MapperScannerConfigurer MSC = new new MapperScannerConfigurer (); 
        msc.setBasePackage ( . "COM *" ); 
        msc.setSqlSessionFactoryBeanName ( "SqlSessionFactory" ); 
        msc.setAnnotationClass (the Repository. class );
         return MSC; 
    }

Guess you like

Origin www.cnblogs.com/xc-xinxue/p/12482199.html