通过配置文件生成代码
配置文件
<?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>
<context id="simple" targetRuntime="MyBatis3Simple">
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/mytests?characterEncoding=utf-8&useSSL=false&serverTimezone=Hongkong"
userId="root" password="123456"/>
<javaModelGenerator targetPackage="com.no.seckill.entity" targetProject="src/main/java">
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="mappers" targetProject="src/main/resources"/>
<javaClientGenerator type="XMLMAPPER" targetPackage="com.no.seckill.dao" targetProject="src/main/java"/>
<table tableName="user" domainObjectName="User"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" >
<!-- <generatedKey column="username" sqlStatement="MYSQL" identity="true" />-->
<columnOverride column="username" jdbcType="VARCHAR" javaType="String" />
<columnOverride column="password" jdbcType="VARCHAR" javaType="String" />
</table>
<table tableName="provider" domainObjectName="Provider"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" >
<!-- <generatedKey column="username" sqlStatement="MYSQL" identity="true" />-->
<columnOverride column="pname" jdbcType="VARCHAR" javaType="String" />
<columnOverride column="pcode" jdbcType="VARCHAR" javaType="String" />
<columnOverride column="country" jdbcType="VARCHAR" javaType="String" />
<columnOverride column="province" jdbcType="VARCHAR" javaType="String" />
<columnOverride column="city" jdbcType="VARCHAR" javaType="String" />
<columnOverride column="address" jdbcType="VARCHAR" javaType="String" />
<columnOverride column="person" jdbcType="VARCHAR" javaType="String" />
<columnOverride column="tel" jdbcType="VARCHAR" javaType="String" />
<columnOverride column="type" jdbcType="VARCHAR" javaType="String" />
</table>
<table tableName="parts" domainObjectName="Parts"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" >
<!-- <generatedKey column="username" sqlStatement="MYSQL" identity="true" />-->
<columnOverride column="pname" jdbcType="VARCHAR" javaType="String" />
<columnOverride column="pcode" jdbcType="VARCHAR" javaType="String" />
<columnOverride column="parname" jdbcType="VARCHAR" javaType="String" />
<columnOverride column="parcode" jdbcType="VARCHAR" javaType="String" />
<columnOverride column="state" jdbcType="VARCHAR" javaType="String" />
<columnOverride column="type" jdbcType="VARCHAR" javaType="String" />
<columnOverride column="parentcode" jdbcType="VARCHAR" javaType="String" />
</table>
</context>
</generatorConfiguration>
想要自动生成代码,必须要在你配置的数据库里面有你已经建好的表
执行代码
mvn mybatis-generator:generate -e
|