使用MyBatis Generator 生成代码

MyBatis Generator (MBG) 可以用如下方式运行。

参考:http://www.mybatis.org/generator/running/running.html

1、通过命令方式运行。如下:

java -jar mybatis-generator-core-x.x.x.jar -configfile generatorConfig.x

java -jar mybatis-generator-core-x.x.x.jar -configfile generatorConfig.xml -overwrite

java -cp mybatis-generator-core-x.x.x.jar org.mybatis.generator.api.ShellRunner -configfile generatorConfig.xml

java -cp mybatis-generator-core-x.x.x.jar org.mybatis.generator.api.ShellRunner -configfile generatorConfig.xml -overwrite

2、通过Maven Plugin方式。

2.1、配置plugin

使用MyBatis Generator 生成代码_第1张图片

2.2、执行 mybatis-generator:generate

使用MyBatis Generator 生成代码_第2张图片

3、通过java编程方式。

3.1) Running MBG from Java with an XML Configuration File

注意官网上的文档有坑,没有如下红线圈代码的话,死活都生成不了文件!原因是targetProject直接读取generatorConfig.xml中的targetProject属性值,然后new File(targetProject)来检测路径是否存在,如果不存在就不会生成任何东西!!!或者你直接在xml中将targetProject属性写成绝对路径,但一般为了灵活性都不会写死。另外:如果你是用idea编辑器,只需用2的方法即可。java 代码生成和eclipse插件方式不能通用。

使用MyBatis Generator 生成代码_第3张图片

4、通过eclipse插件方式。

The eclipse feature can be installed in any of the following ways:

Search for "MyBatis Generator" in the Eclipse marketplace and install directly from the marketplace. You can access the eclipse marketplace in two ways:

1)Take the menu option Help>Eclipse Marketplace... in a running eclipse instance

2)Go to https://marketplace.eclipse.org/

3)使用 mybatis generator eclipse feature

使用MyBatis Generator 生成代码_第4张图片

另:generatorConfig.xml详细说明 http://www.mybatis.org/generator/configreference/xmlconfig.html

你可能感兴趣的:(使用MyBatis Generator 生成代码)