BaseMapper.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /**
  2. * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  3. * <p>
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. * <p>
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. * <p>
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.baomidou.mybatisplus.mapper;
  17. import java.io.Serializable;
  18. import java.util.List;
  19. import java.util.Map;
  20. import org.apache.ibatis.annotations.Param;
  21. import org.apache.ibatis.session.RowBounds;
  22. /**
  23. * <p>
  24. * Mapper 继承该接口后,无需编写 mapper.xml 文件,即可获得CRUD功能
  25. * </p>
  26. * <p>
  27. * 这个 Mapper 支持 id 泛型
  28. * </p>
  29. *
  30. * @author hubin
  31. * @Date 2016-01-23
  32. */
  33. public interface BaseMapper<T> {
  34. /**
  35. * <p>
  36. * 插入一条记录
  37. * </p>
  38. *
  39. * @param entity 实体对象
  40. * @return int
  41. */
  42. Integer insert(T entity);
  43. /**
  44. * <p>
  45. * 插入一条记录
  46. * </p>
  47. *
  48. * @param entity 实体对象
  49. * @return int
  50. */
  51. Integer insertAllColumn(T entity);
  52. /**
  53. * <p>
  54. * 根据 ID 删除
  55. * </p>
  56. *
  57. * @param id 主键ID
  58. * @return int
  59. */
  60. Integer deleteById(Serializable id);
  61. /**
  62. * <p>
  63. * 根据 columnMap 条件,删除记录
  64. * </p>
  65. *
  66. * @param columnMap 表字段 map 对象
  67. * @return int
  68. */
  69. Integer deleteByMap(@Param("cm") Map<String, Object> columnMap);
  70. /**
  71. * <p>
  72. * 根据 entity 条件,删除记录
  73. * </p>
  74. *
  75. * @param wrapper 实体对象封装操作类(可以为 null)
  76. * @return int
  77. */
  78. Integer delete(@Param("ew") Wrapper<T> wrapper);
  79. /**
  80. * <p>
  81. * 删除(根据ID 批量删除)
  82. * </p>
  83. *
  84. * @param idList 主键ID列表
  85. * @return int
  86. */
  87. Integer deleteBatchIds(List<? extends Serializable> idList);
  88. /**
  89. * <p>
  90. * 根据 ID 修改
  91. * </p>
  92. *
  93. * @param entity 实体对象
  94. * @return int
  95. */
  96. Integer updateById(@Param("et") T entity);
  97. /**
  98. * <p>
  99. * 根据 ID 修改
  100. * </p>
  101. *
  102. * @param entity 实体对象
  103. * @return int
  104. */
  105. Integer updateAllColumnById(@Param("et") T entity);
  106. /**
  107. * <p>
  108. * 根据 whereEntity 条件,更新记录
  109. * </p>
  110. *
  111. * @param entity 实体对象
  112. * @param wrapper 实体对象封装操作类(可以为 null)
  113. * @return
  114. */
  115. Integer update(@Param("et") T entity, @Param("ew") Wrapper<T> wrapper);
  116. /**
  117. * <p>
  118. * 根据 ID 查询
  119. * </p>
  120. *
  121. * @param id 主键ID
  122. * @return T
  123. */
  124. T selectById(Serializable id);
  125. /**
  126. * <p>
  127. * 查询(根据ID 批量查询)
  128. * </p>
  129. *
  130. * @param idList 主键ID列表
  131. * @return List<T>
  132. */
  133. List<T> selectBatchIds(List<? extends Serializable> idList);
  134. /**
  135. * <p>
  136. * 查询(根据 columnMap 条件)
  137. * </p>
  138. *
  139. * @param columnMap 表字段 map 对象
  140. * @return List<T>
  141. */
  142. List<T> selectByMap(@Param("cm") Map<String, Object> columnMap);
  143. /**
  144. * <p>
  145. * 根据 entity 条件,查询一条记录
  146. * </p>
  147. *
  148. * @param entity 实体对象
  149. * @return T
  150. */
  151. T selectOne(@Param("ew") T entity);
  152. /**
  153. * <p>
  154. * 根据 Wrapper 条件,查询总记录数
  155. * </p>
  156. *
  157. * @param wrapper 实体对象
  158. * @return int
  159. */
  160. Integer selectCount(@Param("ew") Wrapper<T> wrapper);
  161. /**
  162. * <p>
  163. * 根据 entity 条件,查询全部记录
  164. * </p>
  165. *
  166. * @param wrapper 实体对象封装操作类(可以为 null)
  167. * @return List<T>
  168. */
  169. List<T> selectList(@Param("ew") Wrapper<T> wrapper);
  170. /**
  171. * <p>
  172. * 根据 Wrapper 条件,查询全部记录
  173. * </p>
  174. *
  175. * @param wrapper 实体对象封装操作类(可以为 null)
  176. * @return List<T>
  177. */
  178. List<Map<String, Object>> selectMaps(@Param("ew") Wrapper<T> wrapper);
  179. /**
  180. * <p>
  181. * 根据 Wrapper 条件,查询全部记录
  182. * </p>
  183. *
  184. * @param wrapper 实体对象封装操作类(可以为 null)
  185. * @return List<Object>
  186. */
  187. List<Object> selectObjs(@Param("ew") Wrapper<T> wrapper);
  188. /**
  189. * <p>
  190. * 根据 entity 条件,查询全部记录(并翻页)
  191. * </p>
  192. *
  193. * @param rowBounds 分页查询条件(可以为 RowBounds.DEFAULT)
  194. * @param wrapper 实体对象封装操作类(可以为 null)
  195. * @return List<T>
  196. */
  197. List<T> selectPage(RowBounds rowBounds, @Param("ew") Wrapper<T> wrapper);
  198. /**
  199. * <p>
  200. * 根据 Wrapper 条件,查询全部记录(并翻页)
  201. * </p>
  202. *
  203. * @param rowBounds 分页查询条件(可以为 RowBounds.DEFAULT)
  204. * @param wrapper 实体对象封装操作类
  205. * @return List<Map<String, Object>>
  206. */
  207. List<Map<String, Object>> selectMapsPage(RowBounds rowBounds, @Param("ew") Wrapper<T> wrapper);
  208. }