Intellij code generate plugin. support to generate mybatis dao interface,mapper xml and create table sql base on domain class, use method name to generate mybatis sql.
-
generate mybatis dao interface, mapper xml by domain class, support dao interface jump to mybatis mapper file.
-
refactor mybatis interface method name
- auto complete for mybatis xml.
support following product build version > 141
- Android Studio
- IntelliJ IDEA
- IntelliJ IDEA Community Edition
using IDE plugin system
- Preferences(Settings) > Plugins > Browse repositories... > find"MybatisCodeHelper" > Install Plugin
Manual:
- download
lastest plugin zip
-> Preferences(Settings) > Plugins > Install plugin from disk...
restart IDE.
-
use alt+insert (generate mybatis files) on domain class to generate corresponding dao interface and mapper xml (on mac use with ctrl+N which is the shortcut of generate getter/setter)
-
use alt+enter on mybatis dao interface to generate mybatis sql in mapper xml. and it will also complete your method with param and returnType.
-
in order to use method to generate mapper sql, you need to hava a insert or save or add method in your dao inteface and hava domain class as the first parameter. ( which can be auto generated by domainClass using alt+insert)
-
method name generated mapper sql will use column name defined in domain class type resultMap in mapper xml.
following are current support for domain object field type.
java type | startSupportVersion |
---|---|
java.lang.Integer | v1.2 |
java.lang.Long | v1.2 |
java.lang.FLoat | v1.2 |
java.lang.Double | v1.2 |
java.lang.Boolean | v1.2 |
java.util.Date | v1.2 |
java.lang.String | v1.2 |
java.lang.Byte | v1.2 |
java.math.BigDecimal | v1.2 |
java.lang.Short | v1.2 |
Given a domain class User
field name | type |
---|---|
id | Integer |
userName | String |
password | String |
table name is user
And the resultMap is
<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>
the following is the sql for the method name (method name using upper and lower case is the same for generate)
here are the comparator can be used after field.
comparator | generated sql |
---|---|
between | prop > {} and prop <{} |
betweenOrEqualto | prop >={} and prop <={} v1.3 |
lessThan | prop < {} |
lessThanOrEqualto | prop <={} v1.3 |
greaterThan | prop > {} |
greaterThanOrEqualto | prop >={} v1.3 |
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 method.
support fetch mutiple field,mutiple field query after by.
support orderBy,distinct,findFirst
method name | generated 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 method
method name | generated sql |
---|---|
updateUserNameById | update user set user_name = {} where id = {} |
updateUserNameAndPasswordByIdIn | update user set user_name = {} and password = {} where id in {} |
- delete method
method name | sql |
---|---|
deleteById | delete from user where id = {} |
deleteByUserNameIsNull | delete from user where user_name is null |
- count method support distinct
method name | sql |
---|---|
count | select count(1) from user |
countDistinctUserNameByIdGreaterThan | select count(distinct(user_name)) from user where id > {} |
feature:
- add jump for dao interface and mapper
- use alt+insert to generate dao interface and mapper
- add use method name to generate mapper sql
- add auto completion for dao interface
the project in screencut is from https://github.com/gejun123456/codehelperPluginDemo