Mybatis Generator使用
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mybatis Generator使用相关的知识,希望对你有一定的参考价值。
1)下载Mybatis文件,下载地址如下
https://github.com/mybatis/generator/releases
2)配置 mybatis-generator-core-1.3.2\\lib下 generatorConfig.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> <!-- 数据库驱动Jar包位置(相对路径))--> <classPathEntry location="mysql-connector-java-5.1.25-bin.jar"/> <context id="DB2Tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressDate" value="true"/> <!--是否生成注释--> <property name="suppressAllComments" value="true"/> </commentGenerator> <!--数据库链接URL,用户名、密码 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/system" userId="admin" password="123456"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!-- 生成实体类的包名及位置--> <javaModelGenerator targetPackage="com.hls.model" targetProject="src"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- 生成映射文件的包名及位置--> <sqlMapGenerator targetPackage="com.hls.mapping" targetProject="src"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!-- 生成Dao的包名及位置--> <javaClientGenerator type="XMLMAPPER" targetPackage="com.hls.idao" targetProject="src"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!-- 要生成的表 tableName是数据库中的表名 domainObjectName实体类名--> <table tableName="sys_dict" domainObjectName="Dict" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <table tableName="sys_dict_data" domainObjectName="DictData" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <table tableName="sys_menu" domainObjectName="Menu" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <table tableName="sys_org" domainObjectName="Org" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <table tableName="sys_role" domainObjectName="Role" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <table tableName="sys_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> </context> </generatorConfiguration>
3)打开CMD 进入mybatis-generator-core-1.3.2\\lib 目录并运行命令
Java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite
4)提示MyBatis Generator finished successfully, there were warnings. 就成功了
以上是关于Mybatis Generator使用的主要内容,如果未能解决你的问题,请参考以下文章
Mybatis代码生成器Mybatis-Generator使用详解
使用Mybatis Generator自动生成Mybatis相关代码
IDEA 中使用MyBatis-generator 自动生成MyBatis代码