Mybatis Generator最完整配置详解






 




    
    
    
    
    
    
    
    

    
    
    

    
    
        
    

    
    
        
        
    


    
    
        
        

        
        

        
        

        
        

        
        
    


    
    
        
        
    


    
    
        
        

        
    

    
    

        
        

        
        

        
        

        

        

        

        

        

        
        

        
        


        

        


         
         
             
             

             

             

             

             
         

         
    

 

以上为xml详解

generatorConfig.xml 内容如下:




    
    
    
  
    
    

    
    
            
      
        
        
            
            
        

        
                     connectionURL="${jdbc.url}" userId="${jdbc.username}" password="${jdbc.password}" />

        
        
            
            
        

        
                     targetProject="${project}">
            
            
            
            
        

        
                     targetProject="${resource}">
            
            
        

        
                     targetProject="${project}" type="XMLMAPPER">
            
            
        

        
            

            domainObjectName="pyxisSyncTask" enableCountByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false">
            

            
            
        

    
 

属性文件内容 结构如下

#工程src路径  
project = D:\\Users\\wanglei727\\pyxis\\study_springboot_two\\src\\main\\java
#工程存放mapper.xml路径  
resource = D:\\Users\\wanglei727\\pyxis\\study_springboot_two\\src\\main\\resources
#指定数据连接驱动jar地址  
classPath=D:\\repo\\org\\postgresql\\postgresql\\9.4-1205-jdbc4\\postgresql-9.4-1205-jdbc4.jar

jdbc.driverClassName=org.postgresql.Driver
jdbc.url=jdbc:postgresql://10.20.131.60:7616/d0qer
jdbc.username=dlbdata
jdbc.password=Dpaic1234

采用java 方式生成代码     代码如下 
        List warnings = new ArrayList();
        boolean overwrite = true;
File configFile = new File("D:\\Users\\wanglei727\\pyxis\\study_springboot_two\\src\\main\\resources\\generatorConfig.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = null;
        config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = null;
        myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);

注意事项!!!!!

配置表中不能为schema这个属性赋任何值  否则源码中

catalog ,  schema , tablename , null

        ResultSet rs = databaseMetaData.getColumns(localCatalog, localSchema,
                localTableName, null);

localSchema  这个内容为null  或者为'%'  切记不能填其他内容 否则rs中查询不出所在表的字段

 

转载于:https://my.oschina.net/u/3776411/blog/1617949

你可能感兴趣的:(Mybatis Generator最完整配置详解)