luorh / MyBatisCodeHelper

intellij mybatis plugin add more function to the codehelper.generator plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MyBatisCodeHelper

GitHub release Jetbrains Plugins Version
Downloads Downloads last month

Intellij下代码自动生成插件 支持生成mybatis的dao接口,mapper xml,和建表sql, 支持直接从接口方法名直接生成sql.

  • 根据数据库对象一键生成 Dao接口,Service,Xml,数据库建表Sql文件 提供dao与xml的跳转 generateFile

  • 根据dao中的方法名生成对应的在xml并进行方法补全 find update delete count all_1

安装

支持下面产品编译号为141以上的产品。

  • Android Studio
  • IntelliJ IDEA
  • IntelliJ IDEA Community Edition

使用 IDE 内置插件系统:

  • Preferences(Settings) > Plugins > Browse repositories... > 搜索并找到"MybatisCodeHelper" > Install Plugin

手动:

重启IDE.

使用方法

  • 在数据库对象上使用alt+insert (generate mybatis files)生成对应的dao xml文件等 (mac上使用 ctrl+N 即getter setter对应的快捷键)
  • 当数据库对象添加字段后也可使用alt+insert (generate mybatis files)来生成更新后的xml。(只会更新默认的insert,insertList,update方法 其他自定义的方法不会变)
  • 在mybatis的接口文件上的方法名上使用alt+enter generatedaoxml 生成对应的mybatis sql及方法的补全

需要注意的点

  • 使用方法名生成sql 需要在接口中提供一个insert或save或add方法并以数据库对象为第一参数 (可以通过数据库对象自动生成)
  • 使用方法名生成的sql的字段会从数据库对象对应的resultMap中的数据库字段来设置。

方法名生成sql

数据库对象User

字段名 类型
id Integer
userName String
password String

表名为user

xml中对应的resultMap为

<resultMap id="AllCoumnMap" type="com.codehelper.domain.User">
    <result column="id" property="id"/>
    <result column="user_name" property="userName"/>
    <result column="password" property="password"/>
</resultMap>

以下是方法名与sql的对应关系(方法名的大小写无所谓)

可以跟在字段后面的比较符有

比较符 生成sql
between prop >={} and prop <={}
lessthan prop < {}
greaterthan prop > {}
isnull prop is null
notnull prop is not null
like prop like {}
in prop in {}
notin prop not in {}
not prop != {}
notlike prop not like {}
  • find方法

支持获取多字段,by后面可以设置多个字段的条件
支持orderBy,distinct, findFirst

方法名 sql
find select * from user
findUserName select user_name from user
findById select * from user where id = {}
findByIdGreaterThanAndUserName select * from user where id > {} and user_name = {}
findByIdGreaterThanOrIdLessThan select * from user where id > {} or id < {}
findByIdLessThanAndUserNameIn select * from user where id < {} and user_name in {}
findByUserNameAndPassword select * from user where user_name = {} and password = {}
findUserNameOrderByIdDesc select user_name from user order by id desc
findDistinctUserNameByIdBetween select distinct(user_name) from user where id >= {} and id <={}
findFirstByIdGreaterThan select * from user where id > {} limit 1
findFirst20ByIdLessThan select * from user where id < {} limit 20
findFirst10ByIdGreaterThanOrderByUserName select * from user where id > {} order by user_name limit 10
  • update方法 by后面设置的条件同上
方法名 sql
updateUserNameById update user set user_name = {} where id = {}
updateUserNameAndPasswordByIdIn update user set user_name = {} and password = {} where id in {}
  • delete方法 by后面设置的条件同上
方法名 sql
deleteById delete from user where id = {}
deleteByUserNameIsNull delete from user where user_name is null
  • count方法 by后面设置的条件同上 支持distinct
方法名 sql
count select count(1) from user
countDistinctUserNameByIdGreaterThan select count(distinct(user_name)) from user where id > {}

CHANGELOG

latest

feature:

  • 添加mapper与dao的相互跳转
  • 使用alt+insert来生成dao xml等
  • 添加方法名生成sql
  • 添加方法名自动提示

其他

截图中的项目来自https://github.com/gejun123456/codehelperPluginDemo

About

intellij mybatis plugin add more function to the codehelper.generator plugin


Languages

Language:Java 99.7%Language:FreeMarker 0.3%