Mybatis的逆向工程如何使用

来源:互联网 发布:分销系统源码 编辑:程序博客网 时间:2024/06/14 12:27

1,首先创建一个java工程

 

2,在工程中创建一个lib文件夹,用来存放jar

 

3,导入所需要的jar包,因为是mybatis的逆向工程,所以需要导入mybatis的核心包,而且逆向工程得需要操作数据库,所以得导入关于数据库的包,以及自身的逆向工程的包。

所以就以下的几个包

 

 

4,在工程下面建立一个generate.xml文件

 

 

5,将官方提供的文档直接复制过来,不用自己写

 

6,修改xml里面需要修改的信息,例如所要链接的数据库,以及生成的文件的目录格式,以及要生成什么表

7,创建一个类将 下面的复制进去 直接运行即可

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;

 

public class StartServer {

public void generator()throws Exception{

List<String> warnings = new ArrayList<String>();

boolean overwrite =true;

File configFile = new File("generate.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 {

StartServer startServer = new StartServer();

startServer.generator();

} catch (Exception e) {

e.printStackTrace();

}

}

 

}

点击运行后,就会出现以下结果

 

而我的xml配置的是


 

原创粉丝点击