Mybatis批量删除和更新,中文注释插件

包含3个插件和一个定制的中文注释生成器

  • 批量插入插件 - com.zzh.mbg.plugin.MysqlBatchInsertPlugin
  • 批量更新插件 - com.zzh.mbg.plugin.MysqlBatchUpdatePlugin
  • 批量非空更新插件 - com.zzh.mbg.plugin.MysqlBatchUpdateSelectivePlugin
  • 中文注释生成器 - com.zzh.mbg.GeneralCommentGenerator

MGB Mysql扩展插件源码及使用说明

仅支持Mysql数据库
需要Mybatis3.3及以上版本
基于注解的方式

示例

  1. 注释
/**
 *
 * 对应数据库表: student
 */
public class Student {
    /**
     * 物理主键
     *
     * 对应表字段: student.id
     */
    private Integer id;

    /**
     * 名称
     *
     * 对应表字段: student.name
     */
    private String name;
   
    ...
}
  1. 批量插入/更新/非空更新Mapper,详见示例和测试用例
    /**
     * 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 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 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 list);
  1. 批量插入/更新/非空更新SqlProvider,详见示例和测试用例

批量插入基于:

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 ((?),(?))

你可能感兴趣的:(Mybatis批量删除和更新,中文注释插件)