Intellij IDEA集成mybatis-generator插件自动生成数据库实体操作类

1、File>Settings>Plugins,搜索mybatis-generator,默认没有安装。

2、点击Search in repositories链接,选择idea-mybatis-generator插件,右侧窗口点击install按钮,安装完成后提示重启IDEA。

3、配置idea-mybatis-generator插件

4、加号+新建maven,配置名称:MyBatis Generator,运行命令:mybatis-generator:generate -e

5、配置好后,运行项目选择:MyBatis Generator

6、 配置项目POM.xml文件

            <plugin>
				<groupId>org.mybatis.generator</groupId>
				<artifactId>mybatis-generator-maven-plugin</artifactId>
				<version>1.3.2</version>
				<configuration>
					<!--配置文件的位置-->
					<configurationFile>src/main/resources/MyBatisGenerator.xml</configurationFile>
					<verbose>true</verbose>
					<overwrite>true</overwrite>
				</configuration>
				<executions>
					<execution>
						<id>Generate MyBatis Artifacts</id>
						<goals>
							<goal>generate</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

7、项目resources下要有MyBatisGenerator.xml文件

注:targetProject属性要配置为项目绝对路径,否则无法自动生成相关实体操作类。

IDEA的idea-mybatis-generator插件有个很大的BUG,自动生成的代码会覆盖mapper类中用户自定义接口。

猜你喜欢

转载自blog.csdn.net/fishinhouse/article/details/82529338