学习笔录-SPRING BOOT

spring boot 中使用mybatis自动生成mapper和dao插件

mybatis自动生成插件(mybatis-generator)可以自动生成xml文件和dao文件。这样就大大减少了我们重复编码工作。只需要把精力集中在核心业务上面。使用编辑器是idea,这里默认假设已经把springboot和mybaits整合好的。如果没有可以参见:《springboot2.x整合mybaits及分页插件》文章。步骤:1:在pom.xml中添加mybatis-generator

mybatis自动生成插件(mybatis-generator)可以自动生成xml文件和dao文件。这样就大大减少了我们重复编码工作。只需要把精力集中在核心业务上面。

使用编辑器是idea,这里默认假设已经把spring boot和mybaits整合好的。如果没有可以参见:《spring boot 2.x 整合mybaits及分页插件》文章。

步骤:

1:在pom.xml中添加mybatis-generator插件

2:添加插件需要的配置文件

3:在idea中配置

4:编码测试

一:pom.xml中添加插件

在pom.xml的plugins节点中添加mybatis插件

<!-- 添加mybatis 自动生成插件-->

<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>

<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.2</version>

</dependency>

</dependencies>

</plugin>

C://Users/sizhongkai/AppData/Local/YNote/data/szk_wolf@163.com/40e429d80acb473ab2f28d0a95efdb41/clipboard.png

说明:

C://Users/sizhongkai/AppData/Local/YNote/data/szk_wolf@163.com/f3800db3beca4c228b0403a11e388181/clipboard.png

二:添加自动生产配置文件。

根据pom.xml文件中配置的路径创建generatorConfig.xml内容如下:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE generatorConfiguration

PUBLIC "-//mybatis.org//DTD MyBati

原创不易,完成人机校验,阅读全文

相关推荐

© 凯哥Java · KAIGE.DEV · 记录真实开发问题与工程实践