包含3个插件和一个定制的中文注释生成器
- 批量插入插件 - com.zzh.mbg.plugin.MysqlBatchInsertPlugin
- 批量更新插件 - com.zzh.mbg.plugin.MysqlBatchUpdatePlugin
- 批量非空更新插件 - com.zzh.mbg.plugin.MysqlBatchUpdateSelectivePlugin
- 中文注释生成器 - com.zzh.mbg.GeneralCommentGenerator
注
仅支持Mysql数据库
需要Mybatis3.3及以上版本
基于注解的方式
示例
- 注释
/**
*
* 对应数据库表: student
*/
public class Student {
/**
* 物理主键
*
* 对应表字段: student.id
*/
private Integer id;
/**
* 名称
*
* 对应表字段: 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语法:**
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 ((?),(?))
网友评论