2分钟使用mybatisGenerator自动生成dao和mapper文件——使用cmd命令行

来源:互联网 发布:nba比赛球员数据 编辑:程序博客网 时间:2024/06/07 00:16

1:下载mybatis generator 的jar包

https://github.com/mybatis/


2:撰写xml配置文件


<?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="C:\ihome\jar\mysql\mysql-connector-java\5.1.37\mysql-connector-java-5.1.37.jar"/>    <context id="DB2Tables"    targetRuntime="MyBatis3">        <commentGenerator>            <property name="suppressDate" value="true"/>            <property name="suppressAllComments" value="true"/>        </commentGenerator>        <!--数据库链接地址账号密码-->        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/fms" userId="root" password="huang660612317">        </jdbcConnection>        <javaTypeResolver>            <property name="forceBigDecimals" value="false"/>        </javaTypeResolver>        <!--生成Model类存放位置-->        <javaModelGenerator targetPackage="com.fms.intf.model" targetProject="C:\etraining\fms\fms-intf\src\main\java">            <property name="enableSubPackages" value="true"/>            <property name="trimStrings" value="true"/>        </javaModelGenerator>        <!--生成映射文件存放位置-->        <sqlMapGenerator targetPackage="config.mybatis" targetProject="C:\etraining\fms\fms-web\src\main\resources">            <property name="enableSubPackages" value="true"/>        </sqlMapGenerator>        <!--生成Dao类存放位置-->        <javaClientGenerator type="XMLMAPPER" targetPackage="com.fms.impl" targetProject="C:\etraining\fms\fms-service\src\main\java">            <property name="enableSubPackages" value="true"/>        </javaClientGenerator>        <!--生成对应表及类名-->        <table tableName="r_field_rule" domainObjectName="FieldRule" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>    </context></generatorConfiguration>

classPathEntry    中的路径换成自己的路径<pre name="code" class="html">jdbcConnection    中的路径换成目的数据库的路径,以及用户名密码<pre name="code" class="html">javaModelGenerator  
sqlMapGenerator 
javaClientGenerator  以上三个标签分别为,生成实体类,生成mapper文件,生成dao类的配置  将目的地址进行相应的修改<pre name="code" class="html">table  对应数据库中的每张表,将表面和对应实体类名称进行相应改变即可,如果有多张表,需要使用多个table 

3:执行命令

java -jar C:\ihome\jar\org\mybatis\generator\mybatis-generator-core\1.3.2\mybatis-generator-core-1.3.2.jar  -configfile C:\etraining\fms\fms-web\src\main\resources\config\generatorConfig.xml -overwrite
-jar 的参数为mybatis-generator-core的具体路径

-configfile 的参数为 第二步撰写的xml文件的位置


4success

MyBatis Generator finished successfully.



参考文档:

http://www.cnblogs.com/yjmyzz/p/4210554.html

https://my.oschina.net/lilw/blog/168304



0 0
原创粉丝点击