【精华版】MyBatis生成逆向工程


1.加入相应的pom的jar包


            org.mybatis.generator
            mybatis-generator-core
        


2.idea逆向工程插件


        noodle-mybatis
        
            
                org.mybatis.generator
                mybatis-generator-maven-plugin
                1.3.2
                
                    src/main/resources/mybatis/mybatis-generator.xml
                    true
                    true
                
            
        
    

3.属性文件

jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.connectionURL=jdbc:mysql://127.0.0.1:3306/websocket?useUnicode=true&characterEncoding=utf8
jdbc.userId=root
jdbc.password=welcome
jdbc.driverLocation=E:\\coding\\flxlib\\mysql-connector-java-5.1.35.jar

4.配置文件




    
    
    
    

    

        
            
            
            
        
        
        
        
        
        
        
            
        
        
        
            
            
            
            
        
        
        
            
        
        
        
            
        
        
        


5.生成主文件

package com.flx.noodle.mybatis.generator;

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;

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

/**
 * Created by fenglixiong on 2017/10/22.
 */
public class GeneratorMain {

    public static void main(String[] args) {
        try {
            generator();
            System.out.println("successful!!!");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void generator() throws Exception{
        List warnings = new ArrayList();
        boolean overwrite = true;
        //项目根路径不要有中文,我的有中文,所以使用绝对路径
        File configFile = new File("E:\\coding\\BeefNoodle\\noodle-mybatis\\src\\main\\resources\\mybatis\\mybatis-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);
    }

}

6.tomcat配置

【精华版】MyBatis生成逆向工程_第1张图片



你可能感兴趣的:(持久化框架,精致技术点)