Springboot项目搭建:整合Mybatis-generator

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/java_18945106612/article/details/89517488

1. 在pom中引入依赖

<build>
  <plugins>
	<!-- mybatis generator 自动生成代码插件 -->
	    <plugin>
	        <groupId>org.mybatis.generator</groupId>
	        <artifactId>mybatis-generator-maven-plugin</artifactId>
	        <version>1.3.2</version>
	        <configuration>
	            <configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
	            <overwrite>true</overwrite>
	            <verbose>true</verbose>
	        </configuration>
	    </plugin>
    </plugins>
</build>

2. 编写Mybatis-generator配置文件

提供mybatisgenerator.xml模板

3. 插件自动生成文件(model、mapper.xml、mapper.java)

  • 使用mybatis-genertor插件生成文件

    • Way1
      用run as --> Maven build执行mybatis-generator:generate -e命令生成文件

    • Way2(推荐)
      双击MavenProject->当前项目名称->-Plugins>mybatis-genertor. 运行后自动生成的代码

  • 此时目录结构如下图:
    在这里插入图片描述

4. yml中配置mybatis和mybatis-generator整合

#配置数据库相关
mybatis:
  type-aliases-package: com.extSystem.generator.model
  mapper-locations: classpath:generator/mapping/*.xml

猜你喜欢

转载自blog.csdn.net/java_18945106612/article/details/89517488
今日推荐