1.数据库驱动程序
2.generatorConfig驱动,(下载地址:https://github.com/mybatis/generator/releases)
3.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>
<!--数据库驱动-->
<classPathEntry location="WebRoot/WEB-INF/lib/mysql-connector-java-5.1.8-bin.jar"/>
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--数据库链接地址账号password-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://192.168.1.88:3306/test" userId="zhengshou" password="123456">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!--生成Model类存放位置-->
<javaModelGenerator targetPackage="com.adon.model" targetProject="src">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--生成映射文件存放位置-->
<sqlMapGenerator targetPackage="com.adon.mapping" targetProject="src">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!--生成Dao类存放位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.adon.dao" targetProject="src">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!--生成相应表及类名,tableName和domainObjectName为必选项,分别代表数据库表名和生成的实力类名,其余的能够自己定义去选择(普通情况下均为false)。
-->
<table tableName="user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
</context>
</generatorConfiguration>
打开cmd,进入项目根文件夹,执行一下代码(注意路径问题):
java -jar WebRoot/WEB-INF/lib/mybatis-generator-core-1.3.2.jar -configfile src/config/generatorConfig.xml -overwrite
所有评论(0)