通用mapper的使用——————1

1.导入依赖

springboot:


    tk.mybatis
    mapper-spring-boot-starter
    2.0.4

代码生成MBG:


    org.mybatis.generator
    mybatis-generator-maven-plugin
    1.3.6
    
        
            ${basedir}/src/main/resources/generatorConfig.xml
        
        true
        true
    
    
        
            org.postgresql
            postgresql
            9.4.1211.jre7
        
        
            com.microsoft.sqlserver
            sqljdbc4
            4.0
        
        
            mysql
            mysql-connector-java
            5.1.29
        
        
            tk.mybatis
            mapper
            4.0.0
        
    

执行命令:mybatis-generator:generate

-------------------------------------------------------------------------------------------

generatorConfig.xml配置:





    

        
            
            
            
            
        
        
        
        
        
        
        
        
        
        

        
        

-------------------------------------------------------------------------------------------------------------------

MapperScannerConfigurer :使用tk的扫描
/**
 * 指定扫描 mybaties mapper 的包名
 * @return
 * @throws Exception
 */
public static MapperScannerConfigurer getMapperScannerConfigurer(String sqlSessionFactoryBean, String packageName) throws Exception{
    //通用mapper配置
    Properties properties = new Properties();
    properties.setProperty("mappers", "tk.mybatis.mapper.common.Mapper");
    properties.setProperty("notEmpty", "false");
    MapperScannerConfigurer m=new MapperScannerConfigurer();
    m.setBasePackage(packageName);
    m.setSqlSessionFactoryBeanName(sqlSessionFactoryBean);
    m.setProperties(properties);
    return m;
}

 

 


 

你可能感兴趣的:(通用mapper的使用——————1)