IntelliJ IDEA mybatis-generator逆向工程生成代码

1)导入maven依赖

 
        
            org.mybatis.generator
            mybatis-generator-core
            1.3.7
        

2)在resources资源下添加逆向生成文件





	
	
		
		
			
		
		
		
		

		
			
		

		
		
			
			
		

		
		
			
		

		
		
			
		


		
		

3)创建main方法调用逆向文件,生成JavaBean、Mapper映射

package com.ssm.test;

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.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class TestGen {

    public static void main(String[] args) throws Exception {

        List warnings = new ArrayList();
        boolean overwrite = true;
        ConfigurationParser cp = new ConfigurationParser(warnings);
        //构造输入流对象
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("mbg.xml");
        Configuration config = cp.parseConfiguration(is);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
    }
}

4)如果效果图如下就生成成功了

IntelliJ IDEA mybatis-generator逆向工程生成代码_第1张图片

你可能感兴趣的:(SSM框架)