MyBatis Generator逆向工程生成实体、接口、映射文件等代码

一,参考MyBatis Generator官方教程:http://mybatis.org/generator/index.html

二,maven依赖(目前最新是1.3.7)

        
            org.mybatis.generator
            mybatis-generator-core
            1.3.7
        

三,XML配置(new_generator.xml)





  

    
        
        
        
        
        
        

        
            
            
        

        
        
        

        
            
        

        
        
            
            
            
            
        

        
        
            
        

        
        
            
            
        

      

        
        
            

实体和mapper接口放在java目录下,mapper映射文件放在resources目录下

四,启动代码(NewGeneratorSqlMapUtils.java)

package com.collection.util;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

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

/**
 * @Author: Eric
 * @Description: TODO
 * @Date: 2019/9/17 10:51
 * @Version: 1.0
 **/
public class NewGeneratorSqlMapUtils {

    public static void main(String[] args) throws Exception {
        if(false) {//执行之后就改为false,防止多次执行出现重复的情况
            List warnings = new ArrayList();
            boolean overwrite = true;
            // File configFile = new File("generatorConfig.xml");
            File configFile = new File("C:\\Users\\Administrator\\IdeaProjects\\collection\\src\\main\\resources\\generator\\new_generator.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);
        }
    }
}

五,总结

做个小小的记录,方便后续查看!

你可能感兴趣的:(mybatis,generator,mybatis逆向生成代码,mybatis)