为了账号安全,请及时绑定邮箱和手机立即绑定

mybatis自动生成代码

标签:
JavaScript

第一步:先下载jar包,mybatis-generator-core-1.3.2.jar, mysql-connector-java-5.1.13.jar;
第二步:编写需要生成代码的xml(根据实际的DB, 路径编写)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">;

<generatorConfiguration>

<classPathEntry        location="F:/mybatis/mysql-connector-java-5.1.13.jar"/><context id="my" targetRuntime="MyBatis3">    <commentGenerator>        <property name="suppressDate" value="false"/>        <property name="suppressAllComments" value="true"/>    </commentGenerator>    <jdbcConnection driverClass="com.mysql.jdbc.Driver"                    connectionURL="jdbc:mysql://182.254.128.241:4780/product_wms_test" userId="cdb_outerroot"                    password="zaq1CDE#"/>    <javaModelGenerator targetPackage="cn.eeka.productwms.entity.biz"                        targetProject="F:/mybatis/wms/entity">        <property name="enableSubPackages" value="true"/>        <property name="trimStrings" value="true"/>    </javaModelGenerator>    <sqlMapGenerator targetPackage="mappers"                     targetProject="F:/mybatis/wms/mapper">        <property name="enableSubPackages" value="true"/>    </sqlMapGenerator>    <javaClientGenerator targetPackage="cn.eeka.productwms.dao.biz"                         targetProject="F:/mybatis/wms/dao" type="XMLMAPPER">        <property name="enableSubPackages" value="true"/>    </javaClientGenerator>    <table tableName="PM_ProductInBound" domainObjectName="ProductInBound"           enableCountByExample="false" enableUpdateByExample="false"           enableDeleteByExample="false" enableSelectByExample="false"           selectByExampleQueryId="false">    </table>    <table tableName="PM_ProductInBoundDetail" domainObjectName="ProductInBoundDetail"           enableCountByExample="false" enableUpdateByExample="false"           enableDeleteByExample="false" enableSelectByExample="false"           selectByExampleQueryId="false">    </table></context>

</generatorConfiguration>

第三步: 执行命令
打开命令窗口,切换到mybatis所在包的路径下面,输入命令: java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite

或者 直接双击".bat"文件

注意: xml里面涉及到的一些路径配置,需要根据自己的实际情况填写正确,
如果执行后出现报错,一般有两种原因:
a.把xml中的中文注释都去掉;
b.把xml的编码格式转换成UTF-8 无BOM格式的;

点击查看更多内容
1人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
数据库工程师
手记
粉丝
52
获赞与收藏
361

关注作者,订阅最新文章

阅读免费教程

感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消