IDEA社区版无法使用mybatis-generator插件,借用maven-plugin实现生成mybatis mapper文件

本文介绍了在IDEA社区版中,由于缺少mybatis-generator插件,如何通过引入Maven依赖,配置generatorConfig.xml,并利用Maven插件来生成Mybatis的Mapper文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Maven依赖

<plugin>
	<groupId>org.mybatis.generator</groupId>
	<artifactId>mybatis-generator-maven-plugin</artifactId>
	<version>1.3.6</version>
	<configuration>
		<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
		<verbose>true</verbose>
		<overwrite>true</overwrite>
	</configuration>
	<executions>
		<execution>
			<id>Generate MyBatis Artifacts</id>
			<goals>
				<goal>generate</goal>
			</goals>
		</execution>
	</executions>
	<dependencies>
		<dependency>
			<groupId>org.mybatis.generator</groupId>
			<artifactId>mybatis-generator-core</artifactId>
			<version>1.3.6</version>
		</dependency>
	</dependencies>
</plugin>

配置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>
    <!--location 为本地 mysql jar 包地址,可去maven 仓库取-->
    <classPathEntry
            location="E:/develop_app/repository/mysql/mysql-connector-java/8.0.27/mysql-connector-java-8.0.27.jar"/>
    <context id="my" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="false"/>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!--以下为数据库链接 driverClass  connectionURL userId   password 需修改-->
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                        connectionURL="jdbc:mysql://10.42.216.114:3306/smell?useUnicode=true"
                        userId="root"
                        password="123456"/>
        <!-- 以下为实体类 地址 targetPackage  targetProject -->
        <javaModelGenerator targetPackage="com.tp.strive.smell.model"
                            targetProject=".\src\main\java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!--以下为映射xml文件 路径地址 targetPackage  targetProject -->
        <sqlMapGenerator targetPackage="mapper"
                         targetProject=".\src\main\resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!-- 以下为dao 接口路径地址 targetPackage  targetProject -->
        <javaClientGenerator targetPackage="com.tp.strive.smell.mapper"
                             targetProject=".\src\main\java" type="XMLMAPPER">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!--以下为数据库表 和实体类的对应关系 tableName 表名 domainObjectName 实体类类名 , mapperName =mapper接口命名, sqlProviderName=xml文件命名 mapper接口命名和xml文件如果不配置会自动命名为UserMapper-->
        <table tableName="t_user" domainObjectName="User"
	           mapperName="UserDao" sqlProviderName="UserDao"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
            <!--<columnRenamingRule searchString="^D_"
                                replaceString=""/>-->
        </table>

    </context>
</generatorConfiguration>

使用插件生成mapper文件

双击运行插件即可

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值