包含3個(gè)插件和一個(gè)定制的中文注釋生成器
- 批量插入插件 - com.zzh.mbg.plugin.MysqlBatchInsertPlugin
- 批量更新插件 - com.zzh.mbg.plugin.MysqlBatchUpdatePlugin
- 批量非空更新插件 - com.zzh.mbg.plugin.MysqlBatchUpdateSelectivePlugin
- 中文注釋生成器 - com.zzh.mbg.GeneralCommentGenerator
MGB Mysql擴(kuò)展插件源碼及使用說(shuō)明
注
僅支持Mysql數(shù)據(jù)庫(kù)
需要Mybatis3.3及以上版本
基于注解的方式
示例
- 注釋
/**
*
* 對(duì)應(yīng)數(shù)據(jù)庫(kù)表: student
*/
public class Student {
/**
* 物理主鍵
*
* 對(duì)應(yīng)表字段: student.id
*/
private Integer id;
/**
* 名稱
*
* 對(duì)應(yīng)表字段: student.name
*/
private String name;
...
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated
*/
@InsertProvider(type=StudentSqlProvider.class, method="batchInsert")
@Options(useGeneratedKeys=true,keyProperty="id")
int batchInsert(List<Student> list);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated
*/
@UpdateProvider(type=StudentSqlProvider.class, method="batchUpdateByPrimaryKey")
int batchUpdateByPrimaryKey(List<Student> list);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated
*/
@UpdateProvider(type=StudentSqlProvider.class, method="batchUpdateSelectiveByPrimaryKey")
int batchUpdateSelectiveByPrimaryKey(List<Student> list);
批量插入基于:
INSERT INTO table (field1,field2,field3) VALUES (value1,value2,value3), (value1,value2,value3),(value1,value2,value3)
** 批量更新基于Case When語(yǔ)法:**
UPDATE student
SET NAME = CASE
WHEN (id = ?) THEN
?
WHEN (id = ?) THEN
?
END,
age = CASE
WHEN (id = ?) THEN
?
WHEN (id = ?) THEN
?
END,
gender = CASE
WHEN (id = ?) THEN
?
WHEN (id = ?) THEN
?
END
WHERE
(id) IN ((?),(?))