Mybatis的逆向工程

1、什么是Mybatis逆向工程

mybaits需要程序员自己编写sql语句,mybatis官方提供逆向工程 可以针对单表自动生成mybatis执行所需要的代码(mapper.java,mapper.xml、po..)

企业实际开发中,常用的逆向工程方式:
由于数据库的表生成java代码。

2 、逆向工程步骤

1、下载逆向工程

代码在GitHub可以下载。

2、编写配置文件





































3、 创建Java代码,生成代码

public class GeneratorSqlmap {

public void generator() throws Exception{

List warnings = 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 {
GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap();
generatorSqlmap.generator();
} catch (Exception e) {
e.printStackTrace();
}

}

}

posted @ 2017-07-30 22:14  一条路上的咸鱼  阅读(579)  评论(1)    收藏  举报