IService.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /*
  2. * Copyright (c) 2011-2016, 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.extension.service;
  17. import java.io.Serializable;
  18. import java.util.Collection;
  19. import java.util.List;
  20. import java.util.Map;
  21. import com.baomidou.mybatisplus.core.conditions.Wrapper;
  22. import com.baomidou.mybatisplus.core.pagination.Page;
  23. /**
  24. * <p>
  25. * 顶级 Service
  26. * </p>
  27. *
  28. * @author hubin
  29. * @Date 2016-04-20
  30. */
  31. public interface IService<T> {
  32. /**
  33. * <p>
  34. * 插入一条记录(选择字段,策略插入)
  35. * </p>
  36. *
  37. * @param entity 实体对象
  38. * @return boolean
  39. */
  40. boolean insert(T entity);
  41. /**
  42. * <p>
  43. * 插入一条记录(全部字段)
  44. * </p>
  45. *
  46. * @param entity 实体对象
  47. * @return boolean
  48. */
  49. boolean insertAllColumn(T entity);
  50. /**
  51. * <p>
  52. * 插入(批量),该方法不适合 Oracle
  53. * </p>
  54. *
  55. * @param entityList 实体对象列表
  56. * @return boolean
  57. */
  58. boolean insertBatch(List<T> entityList);
  59. /**
  60. * <p>
  61. * 插入(批量)
  62. * </p>
  63. *
  64. * @param entityList 实体对象列表
  65. * @param batchSize 插入批次数量
  66. * @return boolean
  67. */
  68. boolean insertBatch(List<T> entityList, int batchSize);
  69. /**
  70. * <p>
  71. * 批量修改插入
  72. * </p>
  73. *
  74. * @param entityList 实体对象列表
  75. * @return boolean
  76. */
  77. boolean insertOrUpdateBatch(List<T> entityList);
  78. /**
  79. * <p>
  80. * 批量修改插入
  81. * </p>
  82. *
  83. * @param entityList 实体对象列表
  84. * @param batchSize
  85. * @return boolean
  86. */
  87. boolean insertOrUpdateBatch(List<T> entityList, int batchSize);
  88. /**
  89. * <p>
  90. * 批量修改或插入全部字段
  91. * </p>
  92. *
  93. * @param entityList 实体对象列表
  94. * @return boolean
  95. */
  96. boolean insertOrUpdateAllColumnBatch(List<T> entityList);
  97. /**
  98. * 批量修改或插入全部字段
  99. *
  100. * @param entityList 实体对象列表
  101. * @param batchSize
  102. * @return boolean
  103. */
  104. boolean insertOrUpdateAllColumnBatch(List<T> entityList, int batchSize);
  105. /**
  106. * <p>
  107. * 根据 ID 删除
  108. * </p>
  109. *
  110. * @param id 主键ID
  111. * @return boolean
  112. */
  113. boolean deleteById(Serializable id);
  114. /**
  115. * <p>
  116. * 根据 columnMap 条件,删除记录
  117. * </p>
  118. *
  119. * @param columnMap 表字段 map 对象
  120. * @return boolean
  121. */
  122. boolean deleteByMap(Map<String, Object> columnMap);
  123. /**
  124. * <p>
  125. * 根据 entity 条件,删除记录
  126. * </p>
  127. *
  128. * @param wrapper 实体包装类 {@link Wrapper}
  129. * @return boolean
  130. */
  131. boolean delete(Wrapper<T> wrapper);
  132. /**
  133. * <p>
  134. * 删除(根据ID 批量删除)
  135. * </p>
  136. *
  137. * @param idList 主键ID列表
  138. * @return boolean
  139. */
  140. boolean deleteBatchIds(Collection<? extends Serializable> idList);
  141. /**
  142. * <p>
  143. * 根据 ID 选择修改
  144. * </p>
  145. *
  146. * @param entity 实体对象
  147. * @return boolean
  148. */
  149. boolean updateById(T entity);
  150. /**
  151. * <p>
  152. * 根据 ID 修改全部字段
  153. * </p>
  154. *
  155. * @param entity 实体对象
  156. * @return boolean
  157. */
  158. boolean updateAllColumnById(T entity);
  159. /**
  160. * <p>
  161. * 根据 whereEntity 条件,更新记录
  162. * </p>
  163. *
  164. * @param entity 实体对象
  165. * @param wrapper 实体包装类 {@link Wrapper}
  166. * @return boolean
  167. */
  168. boolean update(T entity, Wrapper<T> wrapper);
  169. /**
  170. * <p>
  171. * 根据ID 批量更新
  172. * </p>
  173. *
  174. * @param entityList 实体对象列表
  175. * @return boolean
  176. */
  177. boolean updateBatchById(List<T> entityList);
  178. /**
  179. * <p>
  180. * 根据ID 批量更新
  181. * </p>
  182. *
  183. * @param entityList 实体对象列表
  184. * @param batchSize 更新批次数量
  185. * @return boolean
  186. */
  187. boolean updateBatchById(List<T> entityList, int batchSize);
  188. /**
  189. * <p>
  190. * 根据ID 批量更新全部字段
  191. * </p>
  192. *
  193. * @param entityList 实体对象列表
  194. * @return boolean
  195. */
  196. boolean updateAllColumnBatchById(List<T> entityList);
  197. /**
  198. * <p>
  199. * 根据ID 批量更新全部字段
  200. * </p>
  201. *
  202. * @param entityList 实体对象列表
  203. * @param batchSize 更新批次数量
  204. * @return boolean
  205. */
  206. boolean updateAllColumnBatchById(List<T> entityList, int batchSize);
  207. /**
  208. * <p>
  209. * TableId 注解存在更新记录,否插入一条记录
  210. * </p>
  211. *
  212. * @param entity 实体对象
  213. * @return boolean
  214. */
  215. boolean insertOrUpdate(T entity);
  216. /**
  217. * 插入或修改一条记录的全部字段
  218. *
  219. * @param entity 实体对象
  220. * @return boolean
  221. */
  222. boolean insertOrUpdateAllColumn(T entity);
  223. /**
  224. * <p>
  225. * 根据 ID 查询
  226. * </p>
  227. *
  228. * @param id 主键ID
  229. * @return T
  230. */
  231. T selectById(Serializable id);
  232. /**
  233. * <p>
  234. * 查询(根据ID 批量查询)
  235. * </p>
  236. *
  237. * @param idList 主键ID列表
  238. * @return List<T>
  239. */
  240. List<T> selectBatchIds(Collection<? extends Serializable> idList);
  241. /**
  242. * <p>
  243. * 查询(根据 columnMap 条件)
  244. * </p>
  245. *
  246. * @param columnMap 表字段 map 对象
  247. * @return List<T>
  248. */
  249. List<T> selectByMap(Map<String, Object> columnMap);
  250. /**
  251. * <p>
  252. * 根据 Wrapper,查询一条记录
  253. * </p>
  254. *
  255. * @param wrapper 实体对象
  256. * @return T
  257. */
  258. T selectOne(Wrapper<T> wrapper);
  259. /**
  260. * <p>
  261. * 根据 Wrapper,查询一条记录
  262. * </p>
  263. *
  264. * @param wrapper {@link Wrapper}
  265. * @return Map<String , Object>
  266. */
  267. Map<String, Object> selectMap(Wrapper<T> wrapper);
  268. /**
  269. * <p>
  270. * 根据 Wrapper,查询一条记录
  271. * </p>
  272. *
  273. * @param wrapper {@link Wrapper}
  274. * @return Object
  275. */
  276. Object selectObj(Wrapper<T> wrapper);
  277. /**
  278. * <p>
  279. * 根据 Wrapper 条件,查询总记录数
  280. * </p>
  281. *
  282. * @param wrapper 实体对象
  283. * @return int
  284. */
  285. int selectCount(Wrapper<T> wrapper);
  286. /**
  287. * <p>
  288. * 查询列表
  289. * </p>
  290. *
  291. * @param wrapper 实体包装类 {@link Wrapper}
  292. * @return
  293. */
  294. List<T> selectList(Wrapper<T> wrapper);
  295. /**
  296. * <p>
  297. * 翻页查询
  298. * </p>
  299. *
  300. * @param page 翻页对象
  301. * @return
  302. */
  303. Page<T> selectPage(Page<T> page);
  304. /**
  305. * <p>
  306. * 查询列表
  307. * </p>
  308. *
  309. * @param wrapper {@link Wrapper}
  310. * @return
  311. */
  312. List<Map<String, Object>> selectMaps(Wrapper<T> wrapper);
  313. /**
  314. * <p>
  315. * 根据 Wrapper 条件,查询全部记录
  316. * </p>
  317. *
  318. * @param wrapper 实体对象封装操作类(可以为 null)
  319. * @return List<Object>
  320. */
  321. List<Object> selectObjs(Wrapper<T> wrapper);
  322. /**
  323. * <p>
  324. * 翻页查询
  325. * </p>
  326. *
  327. * @param page 翻页对象
  328. * @param wrapper {@link Wrapper}
  329. * @return
  330. */
  331. @SuppressWarnings("rawtypes")
  332. Page<Map<String, Object>> selectMapsPage(Page page, Wrapper<T> wrapper);
  333. /**
  334. * <p>
  335. * 翻页查询
  336. * </p>
  337. *
  338. * @param page 翻页对象
  339. * @param wrapper 实体包装类 {@link Wrapper}
  340. * @return
  341. */
  342. Page<T> selectPage(Page<T> page, Wrapper<T> wrapper);
  343. }