一、config.properties文件
#数据库连接jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=gbk jdbc.user=root jdbc.password=1234 # 生成模型的包名 target.model.package=test.entity target.sql.package=test.mapping target.client.package=test.dao # 生成文件要放置路径 target.model.project=src target.sql.project=src target.client.project=src #生成sql中可自动生成日期 gmt.create=F_create_time gmt.modified=F_modify_time
二、config.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> <properties resource="config.properties" /> <classPathEntry location="mysql-connector-java-5.1.26.jar" /> <context id="DB" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressDate" value="true"/> <property name="suppressAllComments" value="true" /> </commentGenerator> <jdbcConnection driverClass="${jdbc.driver}" connectionURL="${jdbc.url}" userId="${jdbc.user}" password="${jdbc.password}"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <javaModelGenerator targetPackage="${target.model.package}" targetProject="${target.model.project}"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <sqlMapGenerator targetPackage="${target.sql.package}" targetProject="${target.sql.project}"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <javaClientGenerator type="XMLMAPPER" targetPackage="${target.client.package}" targetProject="${target.client.project}"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <!-- add your table below --> <table tableName="t_external_bank_card_replace_log" domainObjectName="ExternalBankCardReplaceLog"/> </context> </generatorConfiguration>
三、gen.bat
@ECHO OFF del /f /s /q .\src md .\src java -cp .;mybatis-generator-core-1.3.2.jar org.mybatis.generator.api.ShellRunner -configfile config.xml -overwrite pause @ECHO ON
四、下载jar包
mybatis-generator-core-1.3.2.jar
mysql-connector-java-5.1.26.jar
五、执行gen.bat,即可
时间: 2024-11-10 14:05:54