MyBatis逆向工程

通过逆向工程生成mapper文件,大大提升了开发效率

一、引入依赖

        
            org.mybatis.generator
            mybatis-generator-core
            1.3.5
        

二、编写配置文件






    
        
            
        
        
        

        
            
        

        
        
            
            
        

        
        
            
        

        
        
            
        

        

三、编写启动类

import org.mybatis.generator.api.MyBatisGenerator;
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;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MybatisGenerator {
    public static void main(String[] args) throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException {
        List warnings = new ArrayList();
        boolean overwrite = true;
        //指定配置文件的路径,相对或者绝对路径都可以
        File configFile = new File("E:\\idea\\short-video\\src\\main\\java\\com\\imooc\\utils\\mybatisGenerator\\mbg");
        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)