2分钟使用mybatisGenerator自动生成dao和mapper文件——使用cmd命令行
2016-10-31 17:21
627 查看
1:下载mybatis generator 的jar包
https://github.com/mybatis/
2:撰写xml配置文件
classPathEntry 中的路径换成自己的路径
<pre name="code" class="html">jdbcConnection 中的路径换成目的数据库的路径,以及用户名密码
<pre name="code" class="html">javaModelGenerator
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
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> <!--生成映射文件存放位置--> <sqlMapGeneratortargetPackage="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
相关文章推荐
- 简单三步快速学会使用Mybatis-Generator自动生成entity实体、dao接口以及mapper映射文件(postgre使用实例)
- 使用Mybatis-Generator自动生成entity实体、dao接口以及mapper映射文件
- 使用Mybatis-Generator自动生成Dao、model和mapper.xml相关文件
- 使用Mybatis-Generator自动生成Dao、model和mapper.xml相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- java笔记之使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件2种方法
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件(转)
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件(转)
- 使用mybatis的generator自动生成po及mapper映射文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件(转)
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis Generator结合Ant脚本快速自动生成Model、Mapper等文件的方法
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件(转)
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件(转)