|
2 | 2 |
|
3 | 3 | Mapper3接口有两种形式,一种是提供了一个方法的接口。还有一种是不提供方法,但是继承了多个单方法的接口,一般是某类方法的集合。
|
4 | 4 |
|
5 |
| -例如`SelectMapper`是一个单方法的接口,`BaseSelectMapper`是一个继承了4个基础查询方法的接口。 |
| 5 | +例如`SelectMapper<T>`是一个单方法的接口,`BaseSelectMapper<T>`是一个继承了4个基础查询方法的接口。 |
6 | 6 |
|
7 | 7 | ##基础接口
|
8 | 8 |
|
9 | 9 | ###Select
|
10 | 10 |
|
11 |
| -接口:`SelectMapper`<br> |
| 11 | +接口:`SelectMapper<T>`<br> |
12 | 12 | 方法:`List<T> select(T record);`<br>
|
13 | 13 | 说明:根据实体中的属性值进行查询,查询条件使用等号<br><br>
|
14 | 14 |
|
15 |
| -接口:`SelectByPrimaryKeyMapper`<br> |
| 15 | +接口:`SelectByPrimaryKeyMapper<T>`<br> |
16 | 16 | 方法:`T selectByPrimaryKey(Object key);`<br>
|
17 | 17 | 说明:根据主键字段进行查询,方法参数必须包含完整的主键属性,查询条件使用等号<br>
|
18 | 18 | <br>
|
19 | 19 |
|
20 |
| -接口:`SelectOneMapper`<br> |
| 20 | +接口:`SelectOneMapper<T>`<br> |
21 | 21 | 方法:`T selectOne(T record);`<br>
|
22 | 22 | 说明:根据实体中的属性进行查询,只能有一个返回值,有多个结果是抛出异常,查询条件使用等号<br><br>
|
23 | 23 |
|
24 |
| -接口:`SelectCountMapper`<br> |
| 24 | +接口:`SelectCountMapper<T>`<br> |
25 | 25 | 方法:`int selectCount(T record);`<br>
|
26 | 26 | 说明:根据实体中的属性查询总数,查询条件使用等号<br><br>
|
27 | 27 |
|
28 | 28 | ###Insert
|
29 | 29 |
|
30 |
| -接口:`InsertMapper`<br> |
| 30 | +接口:`InsertMapper<T>`<br> |
31 | 31 | 方法:`int insert(T record);`<br>
|
32 | 32 | 说明:保存一个实体,null的属性也会保存,不会使用数据库默认值。<br><br>
|
33 | 33 |
|
34 |
| -接口:`InsertSelectiveMapper`<br> |
| 34 | +接口:`InsertSelectiveMapper<T>`<br> |
35 | 35 | 方法:`int insertSelective(T record);`<br>
|
36 | 36 | 说明:保存一个实体,null的属性不会保存,会使用数据库默认值。<br><br>
|
37 | 37 |
|
38 | 38 | ###Update
|
39 | 39 |
|
40 |
| -接口:`UpdateByPrimaryKeyMapper`<br> |
| 40 | +接口:`UpdateByPrimaryKeyMapper<T>`<br> |
41 | 41 | 方法:`int updateByPrimaryKey(T record);`<br>
|
42 | 42 | 说明:根据主键更新实体,null值会被更新。<br><br>
|
43 | 43 |
|
44 |
| -接口:`UpdateByPrimaryKeySelectiveMapper`<br> |
| 44 | +接口:`UpdateByPrimaryKeySelectiveMapper<T>`<br> |
45 | 45 | 方法:`int updateByPrimaryKeySelective(T record);`<br>
|
46 | 46 | 说明:根据主键更新属性不为null的值。<br><br>
|
47 | 47 |
|
48 | 48 | ###Delete
|
49 | 49 |
|
50 |
| -接口:`DeleteMapper`<br> |
| 50 | +接口:`DeleteMapper<T>`<br> |
51 | 51 | 方法:`int delete(T record);`<br>
|
52 | 52 | 说明:根据实体属性作为条件进行删除,查询条件使用等号<br><br>
|
53 | 53 |
|
54 |
| -接口:`DeleteByPrimaryKeyMapper`<br> |
| 54 | +接口:`DeleteByPrimaryKeyMapper<T>`<br> |
55 | 55 | 方法:`int deleteByPrimaryKey(Object key);`<br>
|
56 | 56 | 说明:根据主键字段进行删除,方法参数必须包含完整的主键属性<br><br>
|
57 | 57 |
|
58 | 58 | ###base组合接口
|
59 | 59 |
|
60 |
| -接口:`BaseSelectMapper`<br> |
| 60 | +接口:`BaseSelectMapper<T>`<br> |
61 | 61 | 方法:包含上面Select的4个方法<br><br>
|
62 | 62 |
|
63 |
| -接口:`BaseInsertMapper`<br> |
| 63 | +接口:`BaseInsertMapper<T>`<br> |
64 | 64 | 方法:包含上面Insert的2个方法<br><br>
|
65 | 65 |
|
66 |
| -接口:`BaseUpdateMapper`<br> |
| 66 | +接口:`BaseUpdateMapper<T>`<br> |
67 | 67 | 方法:包含上面Update的2个方法<br><br>
|
68 | 68 |
|
69 |
| -接口:`BaseDeleteMapper`<br> |
| 69 | +接口:`BaseDeleteMapper<T>`<br> |
70 | 70 | 方法:包含上面Delete的2个方法<br><br>
|
71 | 71 |
|
72 | 72 | ###CRUD组合接口
|
73 | 73 |
|
74 |
| -接口:`BaseMapper`<br> |
| 74 | +接口:`BaseMapper<T>`<br> |
75 | 75 | 方法:继承了base组合接口中的4个组合接口,包含完整的CRUD方法<br><br>
|
76 | 76 |
|
77 | 77 | ##Example方法
|
78 | 78 |
|
79 |
| -接口:`SelectByExampleMapper`<br> |
| 79 | +接口:`SelectByExampleMapper<T>`<br> |
80 | 80 | 方法:`List<T> selectByExample(Object example);`<br>
|
81 | 81 | 说明:根据Example条件进行查询<br><br>
|
82 | 82 |
|
83 |
| -接口:`SelectCountByExampleMapper`<br> |
| 83 | +接口:`SelectCountByExampleMapper<T>`<br> |
84 | 84 | 方法:`int selectCountByExample(Object example);`<br>
|
85 | 85 | 说明:根据Example条件进行查询总数<br><br>
|
86 | 86 |
|
87 |
| -接口:`UpdateByExampleMapper`<br> |
| 87 | +接口:`UpdateByExampleMapper<T>`<br> |
88 | 88 | 方法:`int updateByExample(@Param("record") T record, @Param("example") Object example);`<br>
|
89 | 89 | 说明:根据Example条件更新实体`record`包含的属性,null值会被更新<br><br>
|
90 | 90 |
|
91 |
| -接口:`UpdateByExampleSelectiveMapper`<br> |
| 91 | +接口:`UpdateByExampleSelectiveMapper<T>`<br> |
92 | 92 | 方法:`int updateByExampleSelective(@Param("record") T record, @Param("example") Object example);`<br>
|
93 | 93 | 说明:根据Example条件更新实体`record`包含的不是null的属性值<br><br>
|
94 | 94 |
|
95 |
| -接口:`DeleteByExampleMapper`<br> |
| 95 | +接口:`DeleteByExampleMapper<T>`<br> |
96 | 96 | 方法:`int deleteByExample(Object example);`<br>
|
97 | 97 | 说明:根据Example条件删除数据<br><br>
|
98 | 98 |
|
99 | 99 | ###Example组合接口
|
100 | 100 |
|
101 |
| -接口:`ExampleMapper`<br> |
| 101 | +接口:`ExampleMapper<T>`<br> |
102 | 102 | 方法:包含上面Example中的5个方法<br><br>
|
103 | 103 |
|
104 | 104 | ##RowBounds
|
105 | 105 |
|
106 | 106 | 默认为<b>内存分页</b>,可以配合[PageHelper](http://git.oschina.net/free/Mybatis_PageHelper)实现物理分页
|
107 | 107 |
|
108 |
| -接口:`SelectRowBoundsMapper`<br> |
| 108 | +接口:`SelectRowBoundsMapper<T>`<br> |
109 | 109 | 方法:`List<T> selectByRowBounds(T record, RowBounds rowBounds);`<br>
|
110 | 110 | 说明:根据实体属性和RowBounds进行分页查询<br><br>
|
111 | 111 |
|
112 |
| -接口:`SelectByExampleRowBoundsMapper`<br> |
| 112 | +接口:`SelectByExampleRowBoundsMapper<T>`<br> |
113 | 113 | 方法:`List<T> selectByExampleAndRowBounds(Object example, RowBounds rowBounds);`<br>
|
114 | 114 | 说明:根据example条件和RowBounds进行分页查询<br><br>
|
115 | 115 |
|
116 | 116 | ###RowBounds组合接口
|
117 | 117 |
|
118 |
| -接口:`RowBoundsMapper`<br> |
| 118 | +接口:`RowBoundsMapper<T>`<br> |
119 | 119 | 方法:包含上面RowBounds中的2个方法<br><br>
|
120 | 120 |
|
121 | 121 | ##special特殊接口
|
122 | 122 |
|
123 | 123 | 这些接口针对部分数据库设计,不是所有数据库都支持
|
124 | 124 |
|
125 |
| -接口:`InsertListMapper`<br> |
| 125 | +接口:`InsertListMapper<T>`<br> |
126 | 126 | 方法:`int insertList(List<T> recordList);`<br>
|
127 | 127 | 说明:批量插入,支持批量插入的数据库可以使用,例如MySQL,H2等,另外该接口限制实体包含`id`属性并且必须为自增列<br><br>
|
128 | 128 |
|
129 |
| -接口:`InsertUseGeneratedKeysMapper`<br> |
| 129 | +接口:`InsertUseGeneratedKeysMapper<T>`<br> |
130 | 130 | 方法:`int InsertUseGeneratedKeysMapper(T record);`<br>
|
131 | 131 | 说明:插入数据,限制为实体包含`id`属性并且必须为自增列,实体配置的主键策略无效<br><br>
|
132 | 132 |
|
133 | 133 | ##MySQL专用
|
134 | 134 |
|
135 |
| -接口:`MySqlMapper`<br> |
| 135 | +接口:`MySqlMapper<T>`<br> |
136 | 136 | 继承方法:`int insertList(List<T> recordList);`<br>
|
137 | 137 | 继承方法:`int InsertUseGeneratedKeysMapper(T record);`<br>
|
138 |
| -说明:该接口不包含方法,继承了special中的`InsertListMapper`和`InsertUseGeneratedKeysMapper`<br><br> |
| 138 | +说明:该接口不包含方法,继承了special中的`InsertListMapper<T>`和`InsertUseGeneratedKeysMapper<T>`<br><br> |
139 | 139 |
|
140 | 140 | ##Mapper<T>接口
|
141 | 141 |
|
| 142 | +接口:`Mapper<T>`<br> |
142 | 143 | 该接口兼容Mapper2.x版本,继承了`BaseMapper<T>`, `ExampleMapper<T>`, `RowBoundsMapper<T>`三个组合接口。
|
143 | 144 |
|
0 commit comments