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