spring-boot + mybatis-enhance-actable 实现mybatis自动建表

spring-boot + mybatis-enhance-actable 实现mybatis自动建表

因为mybatis-enhance-actable是基于mybatis的自动构建工具所以使用前需要先配好mybatis
配置mybatis参照 https://blog.csdn.net/weixin_43866295/article/details/86500610

1.导入依赖

在这里插入图片描述
在这里插入图片描述

因为mybatis-enhance-actable 源码中用到了commons-lang中的集合工具类所以需要导入
commons-lang工具包

2.因为mybatis-enhance-actable是基于mybatis,里面有mapper接口和mapper.xml文件,所以需要配置这两种文件的扫描位置

首先在application.properties中配置mybatis-enhance-actable中 mapper.xml文件的位置,这里的mapperLocations是数组格式,圈的部分即为mybatis-enhance-actable中 mapper.xml文件的位置,后边的是我自己项目中mapper.xml文件的位置
在这里插入图片描述
然后配置配置mybatis-enhance-actable中 mapper接口的位置,同上圈住的部分为mybatis-enhance-actable中 mapper接口的位置

在这里插入图片描述

3.配置mybatis-enhance-actable需要的信息

我这里是创建了一个properties文件,也可以直接写在application.properties文件中
mybatis.table.auto的值有三个 update 是更新, create 是每次都会把表删除重新创建,none为关闭自动建表功能
在这里插入图片描述
4.创建名字为configProperties的bean

因为mybatis-enhance-actable需要在名为configProperties的bean中拿到一些配置信息,所以需要手动添加这个bean,下图为mybatis-enhance-actable 源码部分,可以看到这里只支持mysql与oracle,也可以看到mybatis-enhance-actable 是在bean初始化的时候执行的
在这里插入图片描述
下图为配置名为configProperties的bean
在这里插入图片描述
5.创建实体类,添加注解,跟jpa的注解风格雷同

在这里插入图片描述

然后启动项目之后就可以发现表已经创建好了

猜你喜欢

转载自blog.csdn.net/weixin_43866295/article/details/86515231
今日推荐