spring-boot mybatis代码生成。(注:此工具为idea插件方式,不支持自定义模板,如需要源码模板可自行修改)源码地址
示例生成的代码,包含生成后代码缩依赖的类示例生成项目
- 新建spring-boot项目,示例为gradle构建
依赖片段如下:
compile 'org.springframework.boot:spring-boot-starter-web:2.0.4.RELEASE'
compile 'org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2'
compile 'com.alibaba:druid-spring-boot-starter:1.1.10'
compile 'mysql:mysql-connector-java:5.1.47'
compile 'com.spring4all:swagger-spring-boot-starter:1.7.1.RELEASE'
compile 'org.apache.commons:commons-lang3:3.8'
compile 'commons-collections:commons-collections:3.2.2'
新建项目配置( 注:暂时只支持.yml配置 )
- 此处数据源用于连接数据库,获取数据表信息,以供代码生成。
- druid配置请参考:https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter
- swagger配置请参考:https://github.com/SpringForAll/spring-boot-starter-swagger
安装生成插件
- 方式一:idea-> file-> Settings-> Plugins-> Browser repositories… 搜索“mybatis code generator” 安装。
- 方式二:下载(生成插件) idea-> file-> Settings-> Plugins-> Install plugin from disk… 安装。
生成代码
- idea-> Code-> Code Generator 填写相关信息
- idea-> Code-> Code Generator 填写相关信息
手动更新项目目录
- 如果项目没有自动更新,手动更新即可
- 如果项目没有自动更新,手动更新即可
最终效果
- 生成代码如下
- 生成代码如下