官网所在的地址:http://mybatis.org/generator/quickstart.html#MyBatis3DynamicSql
第一件事,导入相关的包(注意版本,下面仅供参考)
<!-- 代码生成器-->
<!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.4.0</version>
</dependency>
<!-- mysql驱动包 -->
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
</dependency>
1.在项目中创建xml文件
1.1直接在官网上复制粘贴
1.2书写配置
本人写的配置文件
<!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="DB2Tables" targetRuntime="MyBatis3">
<!--取消生成注释-->
<commentGenerator>
<property name="suppressAllComments " value="true"/>
</commentGenerator>
<!-- 数据库连接配置-->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/helper?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8"
userId="用户名"
password="密码">
<property name="nullCatalogMeansCurrent" value="true"/>
</jdbcConnection>
<!-- 指定javaBean生成的位置 -->
<javaModelGenerator targetPackage="com.wang.helper.bean" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 指定sql映射文件生成的位置-->
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 指定dao接口生成的位置,mapper接口-->
<javaClientGenerator targetPackage="com.wang.helper.dao" targetProject="src/main/java"
type="XMLMAPPER">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 指定每个表的生成策略 前面是表名 生成类的名字-->
<table tableName="user" domainObjectName="User"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
<table tableName="entrust" domainObjectName="Entrust"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
</context>
</generatorConfiguration>
2.运行程序,直接复制官网上给的就可以
只需要修改配置文件放那里的路径就可以,运行就可以自动生成
标签:逆向,false,配置文件,generator,用法,mysql,mybatis,org From: https://www.cnblogs.com/wangshileiwu/p/17113865.html