前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >利用mybatis-generator自动生成代码

利用mybatis-generator自动生成代码

作者头像
用户5640963
发布2019-07-28 13:46:24
3840
发布2019-07-28 13:46:24
举报
文章被收录于专栏:卯金刀GG

mybatis-generator 使用maven插件生成代码的步骤,经过测试:

开发工具:myeclipse2014

jdk1.6

一、在pom.xml中添加plugin

<plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <configurationFile>src/main/generator/generatorConfig.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <executions> <execution> <id>Generate MyBatis Artifacts</id> <goals> <goal>generate</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.2</version> </dependency> </dependencies> </plugin>

二、generatorConfig.xml配置文件

<generatorConfiguration> <classPathEntry location="D:/03works/ZYWSPT/tj/ZYWS20160908/cn.qazit.app/src/main/generator/ojdbc14-10.2.0.2.jar" /> <context id="MBG" targetRuntime="MyBatis3" defaultModelType="conditional"> <!--targetRuntime 此属性用于指定生成的代码的运行目标。 --> <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin" /> <plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin"> <property name="searchString" value="Example$" /> <property name="replaceString" value="Criteria" /> </plugin> <commentGenerator> <property name="suppressAllComments" value="false" /> <property name="suppressDate" value="true" /> </commentGenerator> <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@192.168.0.9:1521:orcl" userId="***" password="***"/> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> <!-- 类型解析器 --> </javaTypeResolver>

<javaModelGenerator targetPackage="cn.qazit.app.core.charge.model" targetProject="D:/03works/ZYWSPT/tj/ZYWS20160908/cn.qazit.app/src/main/java"> <!-- 实体类 --> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator>

<sqlMapGenerator targetPackage="cn.qazit.app.core.charge.persistence" targetProject="D:/03works/ZYWSPT/tj/ZYWS20160908/cn.qazit.app/src/main/resources"> <!-- 实体类SQL映射文件 --> <property name="enableSubPackages" value="true" /> </sqlMapGenerator>

<javaClientGenerator type="XMLMAPPER" targetPackage="cn.qazit.app.core.charge.persistence" targetProject="D:/03works/ZYWSPT/tj/ZYWS20160908/cn.qazit.app/src/main/java"> <property name="enableSubPackages" value="true" /> <!-- 接口 --> </javaClientGenerator>

<table tableName="ZYWSPT-ZYWHPJB" domainObjectName="ZywsptZywhpjb" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="true"></table>

配置完成后,选择项目,右键:run as->Goals mybatis-generator:generate,

如果运行报错,提示

No plugin found for prefix 'mybatis-generator' 等等,

请先使用:

run as -> maven clear

run as ->maven install

run as -> Goals mybatis-generator:generate

完成,参考了网上资料,在此谢谢!

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档