一、下载

MyBatisCodeHelperPro插件下载地址:MyBatisCodeHelperPro

二、配置

数据库用的tinyInt 或者 smallInt生成java类型是 byte 和 short 两种类型。在java代码里面操作 byte 和 short 类型比较麻烦,经常需要强制转换,下面是设置使用Integer 来替代byte和short还有使用Java8的日期时间类型

MyBatisCodeHelperPro插件使用

三、使用

根据实体类生成建表sql

按alt+insert

MyBatisCodeHelperPro插件使用

生成的SQL语句:

MyBatisCodeHelperPro插件使用

生成好了建表语句后,到数据库中执行, 然后从数据库来生成crud代码

MyBatisCodeHelperPro插件使用

MyBatisCodeHelperPro插件使用

根据表生成Bean、Dao+mapper和Service

第一步:在Intellij中连接上MySQL数据库,在指定的表上右键

MyBatisCodeHelperPro插件使用

第二步:配置生成信息

MyBatisCodeHelperPro插件使用

第三步:查看各个生成的目录

MyBatisCodeHelperPro插件使用

根据接口中的方法名生成对应的mapper

只需要一个方法名,不需要参数和返回值,输入方法名后,按alt+enter–Generate mybatis sql 就可以生成了

MyBatisCodeHelperPro插件使用

方法名生成sql时支持if test

MyBatisCodeHelperPro插件使用

一键添加@param注解

MyBatisCodeHelperPro插件使用

生成mapper映射文件中resultMap未使用的字段

光标放到resultmap标签type属性值上 -> alt + enter -> generate unUsed properties

MyBatisCodeHelperPro插件使用

根据mapper接口生成mapper映射文件

创建一个接口 -> 光标放到接口名上 -> alt + enter -> generate mybatis mapper for current class -> 选择mapper映射文件位置

MyBatisCodeHelperPro插件使用

生成find方法

根据方法名 直接生成sql代码 方法名有自动提示 单表操作的代码只有写个方法名就好了
find方法

MyBatisCodeHelperPro插件使用

生成测试用例

MyBatisCodeHelperPro插件使用

生成分页查询 (依赖于 pageHelper)

MyBatisCodeHelperPro插件使用

MyBatisCodeHelperPro插件使用

MyBatisCodeHelperPro插件使用

四、DAO层方法的命名规则

find方法

MyBatisCodeHelperPro插件使用

update方法

MyBatisCodeHelperPro插件使用

delete方法

MyBatisCodeHelperPro插件使用

count方法

MyBatisCodeHelperPro插件使用

相关文章: