使用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

2.2、执行 mybatis-generator:generate

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插件方式不能通用。

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

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring 技术笔记Day 1 预热知识一、 基本术语Blob类型,二进制对象Object Graph:对象图...
    OchardBird阅读 1,013评论 0 2
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,131评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,993评论 6 342
  • 参考:Java框架搭建-Maven、Mybatis、Spring MVC整合搭建SSM框架——Spring+Spr...
    VitaAin阅读 1,444评论 1 5
  • 奋笔疾书藐苍茫,青春年少需猖狂。若为粪土违心愿,岂负山河待君赏。莫道人生无再少,少年自走独木桥。览壮丽之神州,窥魂...
    311a949b5048阅读 461评论 0 0