From d8e61cef5a07668a8a4d4d561aa73a9b1c59567b Mon Sep 17 00:00:00 2001 From: hewei Date: Fri, 13 Jan 2017 18:21:24 +0800 Subject: [PATCH] =?UTF-8?q?README.md=E5=A2=9E=E5=8A=A0=E6=96=B0=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 89 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bdc410f..63e32a5 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,13 @@ --------------------------------------- 插件列表: -* 查询单条数据插件 -* MySQL分页插件 -* 数据Model链式构建插件 -* Example Criteria 增强插件(example,andIf) -* Example 目标包修改插件 +* 查询单条数据插件(SelectOneByExamplePlugin) +* MySQL分页插件(LimitPlugin) +* 数据Model链式构建插件(ModelBuilderPlugin) +* Example Criteria 增强插件(CriteriaBuilderPlugin) +* Example 目标包修改插件(ExampleTargetPlugin) +* 批量插入插件(BatchInsertPlugin) +* 逻辑删除插件(LogicalDeletePlugin) --------------------------------------- Maven引用: @@ -16,7 +18,7 @@ Maven引用: com.itfsw mybatis-generator-plugin - 1.0.2 + 1.0.3 ``` --------------------------------------- @@ -210,4 +212,85 @@ Mybatis Generator 插件默认把Model类和Example类都生成到一个包下 +``` +### 6. 批量插入插件 +提供了一个批量插入batchInsert方法,因为方法使用了使用了JDBC的getGenereatedKeys方法返回插入主键,所以只能在MYSQL和SQLServer下使用。 +插件: +```xml + + +``` +使用: +```java +public class Test { + public static void main(String[] args) { + // 构建插入数据 + List list = new ArrayList<>(); + list.add(new Tb.Builder() + .field1(0) + .field2("xx0") + .field3(0) + .field4(new Date()) + .build() + ); + list.add(new Tb.Builder() + .field1(1) + .field2("xx1") + .field3(1) + .field4(new Date()) + .build() + ); + int inserted = this.tbMapper.batchInsert(list); + } +} +``` +### 7. 逻辑删除插件 +因为很多实际项目数据都不允许物理删除,多采用逻辑删除,所以单独为逻辑删除做了一个插件,方便使用。 +插件: +```xml + + + + + + + + + + + + + + +
+
+``` +使用: +```java +public class Test { + public static void main(String[] args) { + // 1. 逻辑删除ByExample + TbExample ex = new TbExample() + .createCriteria() + .andField1EqualTo(1) + .example(); + + this.tbMapper.logicalDeleteByExample(ex); + + // 2. 逻辑删除ByPrimaryKey + this.tbMapper.logicalDeleteByPrimaryKey(1L); + + // 3. 同时Example中提供了一个快捷方法来过滤逻辑删除数据 + TbExample selEx = new TbExample() + .createCriteria() + .andField1EqualTo(1) + // 新增了一个andDeleted方法过滤逻辑删除数据 + .andDeleted(true) + // 当然也可直接使用逻辑删除列的查询方法,我们数据Model中定义了一个逻辑删除常量DEL_FLAG + .andDelFlagEqualTo(Tb.DEL_FLAG) + .example(); + + List list = this.tbMapper.selectByExample(selEx); + } +} ``` \ No newline at end of file