代码拉取完成,页面将自动刷新
为了在项目中快捷方便的代码生成,将mybatis-plus-generator封装为了一个maven的插件
mybatis-plus-generator-maven-plugin
,在要使用的项目pom文件引入该插件,执行mvn命令,即可直接生成代码到项目中,生成基于mybatis-plus
的mapper、service、controller三层结构,包括entity实体类和mapper.xml文件,生成后直接能够满足基本的条件查询和分页查询。下面介绍该插件的使用步骤:
更新记录:
2020-01-11 完善对使用oracle数据源找不到驱动的问题
将源代码导入需要生成代码的项目工程中,执行mvn intall
在要使用插件的工程pom文件中引入该插件,如下案例
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- mybatis-plus generator 自动生成代码插件 -->
<plugin>
<groupId>com.weiller</groupId>
<artifactId>mybatis-plus-generator-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/generator/mp-code-generator-config.yaml</configurationFile>
</configuration>
<dependencies>
<!-- 如果是oracle库,需要额外引入jdbc驱动包,mysql则可忽略 -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${ojdbc.version}</version>
</dependency>
</dependencies>
</plugin>
<!-- mybatis-plus generator 自动生成代码插件 -->
</plugins>
</build>
注意configurationFile
参数为 下一步中配置文件generator-config的位置,该文件类型为yaml
。
配置完整案例
globalConfig:
author: weiller
open: false
idType: INPUT
dateType: ONLY_DATE
enableCache: false
activeRecord: false
baseResultMap: true
baseColumnList: true
swagger2: false
fileOverride: true
dataSourceConfig:
url: jdbc:mysql://localhost:3306/demo?useUnicode=true&useSSL=false&characterEncoding=utf8
driverName: com.mysql.jdbc.Driver
username: root
password: xiweile
packageConfig:
parent: com.weiller
moduleName: rest
entity: model
service: service
serviceImpl: service.impl
mapper: dao
xml: mapper
controller: controller
pathInfo:
entity_path: src\main\java\com\weiller\rest\model
service_path: src\main\java\com\weiller\rest\service
service_impl_path: src\main\java\com\weiller\rest\service\impl
mapper_path: src\main\java\com\weiller\rest\dao
xml_path: src\main\resources\com\weiller\rest\mapper
controller_path: src\main\java\com\weiller\rest\controller
strategyConfig:
naming: underline_to_camel
columnNaming: underline_to_camel
entityLombokModel: true
superMapperClass: com.baomidou.mybatisplus.core.mapper.BaseMapper
superServiceClass: com.baomidou.mybatisplus.extension.service.IService
superServiceImplClass: com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
controllerMappingHyphenStyle: true
restControllerStyle: true
tablePrefix:
include:
- t_user
配置项参数解释:https://mp.baomidou.com/config/generator-config.html#基本配置
在命令工具中,进入到要生成项目的根目录(即pom.xml目录),执行以下命令
mvn mybatis-plus-generator:generator
如果是使用InterlliJ IDEA工具,使用更加方便,步骤如下图:
生成结果如下:
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。