MyBatis Generator
能够自动生成 mapper文件,entity实体类等,方便开发人员使用。
引入的依赖、插件
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<configuration>
<configurationFile>D:\ideaProject\whale-user\whale-user-core\src\main\resources\mybatis-generator\generatorConfig.xml
</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
</plugin>
注意配置文件地址可能需要修改
添加配置文件
<?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>
<!-- 连接数据库jar包的路径-->
<classPathEntry location="D:\repository\org\mariadb\jdbc\mariadb-java-client\2.1.2\mariadb-java-client-2.1.2.jar"/>
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true"/>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--数据库连接参数 -->
<jdbcConnection
driverClass="org.mariadb.jdbc.Driver"
connectionURL="jdbc:mariadb://172.0.0.1:3306/test?characterEncoding=UTF-8"
userId="root"
password="111111">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 实体类的包名和存放路径 -->
<javaModelGenerator targetPackage="com.sensetime.scg.whale.user.entity" targetProject="D:\ideaProject\whale-user\whale-user-client\src\main\java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- 生成映射文件*.xml的位置-->
<sqlMapGenerator targetPackage="mapper" targetProject="D:\ideaProject\whale-user\whale-user-core\src\main\resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.sensetime.scg.whale.user.dao" targetProject="D:\ideaProject\whale-user\whale-user-core\src\main\java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- tableName:数据库中的表名或视图名;domainObjectName:生成的实体类的类名-->
<table tableName="info_resource" domainObjectName="Resource"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"/>
<!--
<table tableName="xxx" domainObjectName="xxx"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"/>
-->
</context>
</generatorConfiguration>
生成的文件在按照自己的项目结构自己定义,此处我使用的是绝对路径

执行生成
双击插件就可以执行

MyBatisGenerator 是一款强大的代码生成工具,能自动生成Mapper文件、实体类等,简化开发流程。通过配置Maven插件和generatorConfig.xml文件,可以设定数据库连接、目标包路径等。在配置完成后,执行插件即可自动创建对应文件,提高开发效率。
2万+

被折叠的 条评论
为什么被折叠?



