1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2014 [email protected]
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+
25
+ package com .github .abel533 .mapper .special ;
26
+
27
+ import com .github .abel533 .provider .SpecialProvider ;
28
+ import org .apache .ibatis .annotations .InsertProvider ;
29
+ import org .apache .ibatis .annotations .Options ;
30
+
31
+ /**
32
+ * 通用Mapper接口,特殊方法,批量插入,支持批量插入的数据库都可以使用,例如mysql,h2等
33
+ *
34
+ * @param <T> 不能为空
35
+ * @author liuzh
36
+ */
37
+ public interface InsertUseGeneratedKeysMapper <T > {
38
+
39
+ /**
40
+ * 插入,支持数据库自增字段必须是id,支持回写
41
+ *
42
+ * @param record
43
+ * @return
44
+ */
45
+ @ Options (useGeneratedKeys = true , keyProperty = "id" )
46
+ @ InsertProvider (type = SpecialProvider .class , method = "dynamicSQL" )
47
+ int InsertUseGeneratedKeysMapper (T record );
48
+
49
+ /**
50
+ * ======如果主键不是id怎么用?==========
51
+ * 假设主键的属性名是uid,那么新建一个Mapper接口如下
52
+ * <pre>
53
+ public interface InsertUidMapper<T> {
54
+ @Options(useGeneratedKeys = true, keyProperty = "id")
55
+ @InsertProvider(type = SpecialProvider.class, method = "dynamicSQL")
56
+ int InsertUseGeneratedKeysMapper(T record);
57
+ }
58
+ * 只要修改keyProperty = "uid"就可以
59
+ *
60
+ * 然后让你自己的Mapper继承InsertUidListMapper<T>即可
61
+ *
62
+ * </pre>
63
+ */
64
+ }
0 commit comments