1.首先在pom文件里面加dependency依赖
org.mybatis mybatis-spring ${mybatis-spring} org.mybatis.generator mybatis-generator-core 1.3.2 mysql mysql-connector-java 5.1.8
2.在pom文件里面加入插件依赖
org.apache.maven.plugins maven-source-plugin 2.2.1 attach-source jar **/org/** org.apache.maven.plugins maven-jar-plugin 2.4 attach-jar jar true org.mybatis.generator.api.ShellRunner **/org/**
3.创建generatorConfig.xml
4.创建自动生成逆向工程的类
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;/** * mybatis逆向工程 * Created by fwj on 16-3-18. */public class Generator { public void generator() throws Exception { Listwarnings = new ArrayList (); boolean overwrite = true; //指定 逆向工程配置文件 File configFile = new File("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 generatorSqlmap = new Generator(); generatorSqlmap.generator(); } catch (Exception e) { e.printStackTrace(); } }}