JAVA逆向工程配置MAVEN,一个表的增删改查所有代码自动生成

 

可以专门对一个表生成所有的增删改查需要的文件

多表联合的时候需要自己生成后手动修改了


代码自动生成的pom文件



			log4j
			log4j
			1.2.15
			 
                            
                javax.jms 
                jms 
              
                             
                 com.sun.jdmk           
                  jmxtools 
              
                          
                  com.sun.jmx 
                  jmxri 
             
          
		

	
        org.mybatis.generator
        mybatis-generator-core
        1.3.5
    




	
           org.mybatis.generator
           mybatis-generator-maven-plugin
           1.3.2
           
                    
                        Generate Mybatis Files
                        
                            generate
                        
                        generate
                        
                            true
                            true
                        
                    
                

 

           
           
                 MySQL
                 mysql-connector-java
                 5.1.38
              
              
                 org.mybatis.generator
           mybatis-generator-core
                 1.3.5
              
              
                 org.mybatis
                 mybatis
                 3.4.2
              
             
     

自动生成的 配置文件丢在和spring的配置文件中

整个文件唯一要改的地方就是这个文件最后面的要生成的表

tableName="你要生成的表" domainObjectName="生成文件头的名字"



 

 
 
 
 
 
 
  
 
 
 





 
 
  
 



 

 
 
 



   

 
    
 





  

 

直接运行main方法就可以自动 

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
public class Generator {
	public static void generator() throws Exception{

        List warnings = new ArrayList();
        boolean overwrite = true;
        //指定逆向工程配置文件
        File configFile = new File("src/main/resources/conf/generatorConfig.xml"); 
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
    } 

    public static void main(String[] args) throws Exception {
        try {
            generator();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

 

你可能感兴趣的:(java)