使用mybatis-generator-core实现逆向工程

使用mybatis-generator-core实现逆向工程

  1. 添加jar包

    • lib/mybatis-generator-core-1.3.2.jar
    • mybatis-3.4.4.jar
    • mysql-connector-java-5.1.44.jar或者mysql-connector-java-8.0.13.jar
  2. 添加generatorConfig.xml配置

    • 
      
      
      
          
          
          
          
              
              
              
                  
              
              
              
              
              
      
              
              
                  
              
              
              
                  
                  
              
              
              
                  
              
              
              
                  
              
              
              
    • 添加测试类

      • import java.io.File;
        import java.io.IOException;
        import java.sql.SQLException;
        import java.util.ArrayList;
        import java.util.List;
        
        import org.mybatis.generator.api.MyBatisGenerator;
        import org.mybatis.generator.api.ShellCallback;
        import org.mybatis.generator.config.Configuration;
        import org.mybatis.generator.config.xml.ConfigurationParser;
        import org.mybatis.generator.exception.InvalidConfigurationException;
        import org.mybatis.generator.exception.XMLParserException;
        import org.mybatis.generator.internal.DefaultShellCallback;
        
        public class GenerateUtils {
        
            public static void main(String[] args) throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException {
                File f = new File("target/classes/generatorConfig.xml");
        
                List warnings = new ArrayList();
                ConfigurationParser parser = new ConfigurationParser(warnings);
        
                Configuration configuration = parser.parseConfiguration(f);
        
                boolean overwrite = true;
                ShellCallback shellCallback = new DefaultShellCallback(overwrite);
                MyBatisGenerator generator = new MyBatisGenerator(configuration, shellCallback, warnings);
        
                generator.generate(null);
        
                System.out.println("OK!");
            }
        }
        
    • 你可能感兴趣的:(使用mybatis-generator-core实现逆向工程)