MyBatis逆向工程
新建 maven 工程
<build>
<plugins>
<!--mybatis代码自动生成插件-->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.6</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.45</version>
</dependency>
</dependencies>
<configuration>
<!--配置文件的位置-->
<configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
</build>
在 resources 目录下创建 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>
<context id="mysqlGenerator" targetRuntime="MyBatis3Simple">
<!-- 序列化插件 -->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
<!-- toString 插件,生成toString 方法 -->
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
<commentGenerator>
<property name="suppressDate" value="true"/>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- mysql 驱动 5.1.45 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql:///ylb"
userId="root"
password="root"/>
<javaModelGenerator targetPackage="com.bjpowernode.ylb.entity" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--生成映射文件存放位置-->
<sqlMapGenerator targetPackage="mapping" targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<javaClientGenerator targetPackage="com.bjpowernode.ylb.mapper" type="XMLMAPPER" targetProject="src/main/java">
<!-- 在targetPackage的基础上,根据数据库的schema再生成一层package,最终生成的类放在这个package下,默认为false -->
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 数据库表名及对应的Java模型类名 -->
<table tableName="b_product_info" domainObjectName="ProductEntity"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
enableSelectByPrimaryKey="false"
enableUpdateByPrimaryKey="false"
enableDeleteByPrimaryKey="false"
selectByPrimaryKeyQueryId="false"
selectByExampleQueryId="false"
/>
<table tableName="b_bid_info" domainObjectName="BidEntity"/>
<table tableName="b_income_record" domainObjectName="IncomeEntity"/>
<table tableName="b_recharge_record" domainObjectName="RechargeEntity"/>
<table tableName="u_user" domainObjectName="UserEntity"/>
<table tableName="u_finance_account" domainObjectName="AccountEntity"/>
</context>
</generatorConfiguration>
可选参数,默认都是true,会自动生成增删改查,就弄成默认的即可。如果改为 false,有可能不会自动生成 ResultMap
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
enableSelectByPrimaryKey="false"
enableUpdateByPrimaryKey="false"
enableDeleteByPrimaryKey="false"
selectByPrimaryKeyQueryId="false"
selectByExampleQueryId="false"

浙公网安备 33010602011771号