Db.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. package com.baomidou.mybatisplus.extension.toolkit;
  2. import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
  3. import com.baomidou.mybatisplus.core.enums.SqlMethod;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.baomidou.mybatisplus.core.metadata.TableInfo;
  6. import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
  7. import com.baomidou.mybatisplus.core.toolkit.*;
  8. import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
  9. import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
  10. import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
  11. import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
  12. import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper;
  13. import com.baomidou.mybatisplus.extension.service.IService;
  14. import org.apache.ibatis.binding.MapperMethod;
  15. import org.apache.ibatis.logging.Log;
  16. import org.apache.ibatis.logging.LogFactory;
  17. import java.io.Serializable;
  18. import java.util.*;
  19. import java.util.stream.Collectors;
  20. /**
  21. * 以静态方式调用Service中的函数
  22. *
  23. * @author VampireAchao
  24. * @since 2022-05-03
  25. */
  26. public class Db {
  27. private static final Log log = LogFactory.getLog(Db.class);
  28. private Db() {
  29. /* Do not new me! */
  30. }
  31. /**
  32. * 插入一条记录(选择字段,策略插入)
  33. *
  34. * @param entity 实体对象
  35. */
  36. public static <T> boolean save(T entity) {
  37. if (Objects.isNull(entity)) {
  38. return false;
  39. }
  40. @SuppressWarnings("unchecked")
  41. Class<T> entityClass = (Class<T>) entity.getClass();
  42. Integer result = SqlHelper.execute(entityClass, baseMapper -> baseMapper.insert(entity));
  43. return SqlHelper.retBool(result);
  44. }
  45. /**
  46. * 插入(批量)
  47. *
  48. * @param entityList 实体对象集合
  49. */
  50. public static <T> boolean saveBatch(Collection<T> entityList) {
  51. return saveBatch(entityList, IService.DEFAULT_BATCH_SIZE);
  52. }
  53. /**
  54. * 插入(批量)
  55. *
  56. * @param entityList 实体对象集合
  57. * @param batchSize 插入批次数量
  58. */
  59. public static <T> boolean saveBatch(Collection<T> entityList, int batchSize) {
  60. if (CollectionUtils.isEmpty(entityList)) {
  61. return false;
  62. }
  63. Class<T> entityClass = getEntityClass(entityList);
  64. Class<?> mapperClass = ClassUtils.toClassConfident(getTableInfo(entityClass).getCurrentNamespace());
  65. String sqlStatement = SqlHelper.getSqlStatement(mapperClass, SqlMethod.INSERT_ONE);
  66. return SqlHelper.executeBatch(entityClass, LogFactory.getLog(Db.class), entityList, batchSize, (sqlSession, entity) -> sqlSession.insert(sqlStatement, entity));
  67. }
  68. /**
  69. * 批量修改插入
  70. *
  71. * @param entityList 实体对象集合
  72. */
  73. public static <T> boolean saveOrUpdateBatch(Collection<T> entityList) {
  74. return saveOrUpdateBatch(entityList, IService.DEFAULT_BATCH_SIZE);
  75. }
  76. /**
  77. * 批量修改插入
  78. *
  79. * @param entityList 实体对象集合
  80. * @param batchSize 每次的数量
  81. */
  82. public static <T> boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize) {
  83. if (CollectionUtils.isEmpty(entityList)) {
  84. return false;
  85. }
  86. Class<T> entityClass = getEntityClass(entityList);
  87. TableInfo tableInfo = getTableInfo(entityClass);
  88. Class<?> mapperClass = ClassUtils.toClassConfident(tableInfo.getCurrentNamespace());
  89. String keyProperty = tableInfo.getKeyProperty();
  90. Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for primary key from entity!");
  91. return SqlHelper.saveOrUpdateBatch(entityClass, mapperClass, LogFactory.getLog(Db.class), entityList, batchSize, (sqlSession, entity) -> {
  92. Object idVal = tableInfo.getPropertyValue(entity, keyProperty);
  93. return StringUtils.checkValNull(idVal)
  94. || CollectionUtils.isEmpty(sqlSession.selectList(SqlHelper.getSqlStatement(mapperClass, SqlMethod.SELECT_BY_ID), entity));
  95. }, (sqlSession, entity) -> {
  96. MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>();
  97. param.put(Constants.ENTITY, entity);
  98. sqlSession.update(SqlHelper.getSqlStatement(mapperClass, SqlMethod.UPDATE_BY_ID), param);
  99. });
  100. }
  101. /**
  102. * 根据 ID 删除
  103. *
  104. * @param id 主键ID
  105. * @param entityClass 实体类
  106. */
  107. public static <T> boolean removeById(Serializable id, Class<T> entityClass) {
  108. return SqlHelper.execute(entityClass, baseMapper -> SqlHelper.retBool(baseMapper.deleteById(id)));
  109. }
  110. /**
  111. * 根据实体(ID)删除
  112. *
  113. * @param entity 实体
  114. */
  115. public static <T> boolean removeById(T entity) {
  116. if (Objects.isNull(entity)) {
  117. return false;
  118. }
  119. @SuppressWarnings("unchecked")
  120. Class<T> entityClass = (Class<T>) entity.getClass();
  121. return SqlHelper.execute(entityClass, baseMapper -> SqlHelper.retBool(baseMapper.deleteById(entity)));
  122. }
  123. /**
  124. * 根据 entity 条件,删除记录
  125. *
  126. * @param queryWrapper 实体包装类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
  127. */
  128. public static <T> boolean remove(AbstractWrapper<T, ?, ?> queryWrapper) {
  129. return SqlHelper.execute(getEntityClass(queryWrapper), baseMapper -> SqlHelper.retBool(baseMapper.delete(queryWrapper)));
  130. }
  131. /**
  132. * 根据 ID 选择修改
  133. *
  134. * @param entity 实体对象
  135. */
  136. public static <T> boolean updateById(T entity) {
  137. if (Objects.isNull(entity)) {
  138. return false;
  139. }
  140. @SuppressWarnings("unchecked")
  141. Class<T> entityClass = (Class<T>) entity.getClass();
  142. return SqlHelper.execute(entityClass, baseMapper -> SqlHelper.retBool(baseMapper.updateById(entity)));
  143. }
  144. /**
  145. * 根据 UpdateWrapper 条件,更新记录 需要设置sqlset
  146. *
  147. * @param updateWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper}
  148. */
  149. public static <T> boolean update(AbstractWrapper<T, ?, ?> updateWrapper) {
  150. return update(null, updateWrapper);
  151. }
  152. /**
  153. * 根据 whereEntity 条件,更新记录
  154. *
  155. * @param entity 实体对象
  156. * @param updateWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper}
  157. */
  158. public static <T> boolean update(T entity, AbstractWrapper<T, ?, ?> updateWrapper) {
  159. return SqlHelper.execute(getEntityClass(updateWrapper), baseMapper -> SqlHelper.retBool(baseMapper.update(entity, updateWrapper)));
  160. }
  161. /**
  162. * 根据ID 批量更新
  163. *
  164. * @param entityList 实体对象集合
  165. */
  166. public static <T> boolean updateBatchById(Collection<T> entityList) {
  167. return updateBatchById(entityList, IService.DEFAULT_BATCH_SIZE);
  168. }
  169. /**
  170. * 根据ID 批量更新
  171. *
  172. * @param entityList 实体对象集合
  173. * @param batchSize 更新批次数量
  174. */
  175. public static <T> boolean updateBatchById(Collection<T> entityList, int batchSize) {
  176. Class<T> entityClass = getEntityClass(entityList);
  177. TableInfo tableInfo = getTableInfo(entityClass);
  178. String sqlStatement = SqlHelper.getSqlStatement(ClassUtils.toClassConfident(tableInfo.getCurrentNamespace()), SqlMethod.UPDATE_BY_ID);
  179. return SqlHelper.executeBatch(entityClass, LogFactory.getLog(Db.class), entityList, batchSize, (sqlSession, entity) -> {
  180. MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>();
  181. param.put(Constants.ENTITY, entity);
  182. sqlSession.update(sqlStatement, param);
  183. });
  184. }
  185. /**
  186. * 删除(根据ID 批量删除)
  187. *
  188. * @param list 主键ID或实体列表
  189. * @param entityClass 实体类
  190. */
  191. public static <T> boolean removeByIds(Collection<? extends Serializable> list, Class<T> entityClass) {
  192. return SqlHelper.execute(entityClass, baseMapper -> SqlHelper.retBool(baseMapper.deleteBatchIds(list)));
  193. }
  194. /**
  195. * 根据 columnMap 条件,删除记录
  196. *
  197. * @param columnMap 表字段 map 对象
  198. * @param entityClass 实体类
  199. */
  200. public static <T> boolean removeByMap(Map<String, Object> columnMap, Class<T> entityClass) {
  201. return SqlHelper.execute(entityClass, baseMapper -> SqlHelper.retBool(baseMapper.deleteByMap(columnMap)));
  202. }
  203. /**
  204. * TableId 注解存在更新记录,否插入一条记录
  205. *
  206. * @param entity 实体对象
  207. */
  208. public static <T> boolean saveOrUpdate(T entity) {
  209. if (Objects.isNull(entity)) {
  210. return false;
  211. }
  212. @SuppressWarnings("unchecked")
  213. Class<T> entityClass = (Class<T>) entity.getClass();
  214. TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass);
  215. Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!");
  216. String keyProperty = tableInfo.getKeyProperty();
  217. Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!");
  218. Object idVal = tableInfo.getPropertyValue(entity, tableInfo.getKeyProperty());
  219. return StringUtils.checkValNull(idVal) || Objects.isNull(getById((Serializable) idVal, entityClass)) ? save(entity) : updateById(entity);
  220. }
  221. /**
  222. * 根据 ID 查询
  223. *
  224. * @param id 主键ID
  225. * @param entityClass 实体类
  226. */
  227. public static <T> T getById(Serializable id, Class<T> entityClass) {
  228. return SqlHelper.execute(entityClass, baseMapper -> baseMapper.selectById(id));
  229. }
  230. /**
  231. * 根据 Wrapper,查询一条记录 <br/>
  232. * <p>结果集,如果是多个会抛出异常,随机取一条加上限制条件 wrapper.last("LIMIT 1")</p>
  233. *
  234. * @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
  235. */
  236. public static <T> T getOne(AbstractWrapper<T, ?, ?> queryWrapper) {
  237. return getOne(queryWrapper, true);
  238. }
  239. /**
  240. * 根据 Wrapper,查询一条记录
  241. *
  242. * @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
  243. * @param throwEx 有多个 result 是否抛出异常
  244. */
  245. public static <T> T getOne(AbstractWrapper<T, ?, ?> queryWrapper, boolean throwEx) {
  246. Class<T> entityClass = getEntityClass(queryWrapper);
  247. if (throwEx) {
  248. return SqlHelper.execute(entityClass, baseMapper -> baseMapper.selectOne(queryWrapper));
  249. }
  250. return SqlHelper.execute(entityClass, baseMapper -> SqlHelper.getObject(log, baseMapper.selectList(queryWrapper)));
  251. }
  252. /**
  253. * 查询(根据 columnMap 条件)
  254. *
  255. * @param columnMap 表字段 map 对象
  256. * @param entityClass 实体类
  257. */
  258. public static <T> List<T> listByMap(Map<String, Object> columnMap, Class<T> entityClass) {
  259. return SqlHelper.execute(entityClass, baseMapper -> baseMapper.selectByMap(columnMap));
  260. }
  261. /**
  262. * 查询(根据ID 批量查询)
  263. *
  264. * @param idList 主键ID列表
  265. * @param entityClass 实体类
  266. */
  267. public static <T> List<T> listByIds(Collection<? extends Serializable> idList, Class<T> entityClass) {
  268. return SqlHelper.execute(entityClass, baseMapper -> baseMapper.selectBatchIds(idList));
  269. }
  270. /**
  271. * 根据 Wrapper,查询一条记录
  272. *
  273. * @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
  274. */
  275. public static <T> Map<String, Object> getMap(AbstractWrapper<T, ?, ?> queryWrapper) {
  276. return SqlHelper.execute(getEntityClass(queryWrapper), baseMapper -> SqlHelper.getObject(log, baseMapper.selectMaps(queryWrapper)));
  277. }
  278. /**
  279. * 查询总记录数
  280. *
  281. * @param entityClass 实体类
  282. * @see Wrappers#emptyWrapper()
  283. */
  284. public static <T> long count(Class<T> entityClass) {
  285. return SqlHelper.execute(entityClass, baseMapper -> baseMapper.selectCount(null));
  286. }
  287. /**
  288. * 根据 Wrapper 条件,查询总记录数
  289. *
  290. * @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
  291. */
  292. public static <T> long count(AbstractWrapper<T, ?, ?> queryWrapper) {
  293. return SqlHelper.execute(getEntityClass(queryWrapper), baseMapper -> baseMapper.selectCount(queryWrapper));
  294. }
  295. /**
  296. * 查询列表
  297. *
  298. * @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
  299. */
  300. public static <T> List<T> list(AbstractWrapper<T, ?, ?> queryWrapper) {
  301. Class<T> entityClass = getEntityClass(queryWrapper);
  302. return SqlHelper.execute(entityClass, baseMapper -> baseMapper.selectList(queryWrapper));
  303. }
  304. /**
  305. * 查询所有
  306. *
  307. * @param entityClass 实体类
  308. * @see Wrappers#emptyWrapper()
  309. */
  310. public static <T> List<T> list(Class<T> entityClass) {
  311. return SqlHelper.execute(entityClass, baseMapper -> baseMapper.selectList(null));
  312. }
  313. /**
  314. * 查询列表
  315. *
  316. * @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
  317. */
  318. public static <T> List<Map<String, Object>> listMaps(AbstractWrapper<T, ?, ?> queryWrapper) {
  319. return SqlHelper.execute(getEntityClass(queryWrapper), baseMapper -> baseMapper.selectMaps(queryWrapper));
  320. }
  321. /**
  322. * 查询所有列表
  323. *
  324. * @param entityClass 实体类
  325. * @see Wrappers#emptyWrapper()
  326. */
  327. public static <T> List<Map<String, Object>> listMaps(Class<T> entityClass) {
  328. return SqlHelper.execute(entityClass, baseMapper -> baseMapper.selectMaps(null));
  329. }
  330. /**
  331. * 查询全部记录
  332. *
  333. * @param entityClass 实体类
  334. */
  335. public static <T> List<T> listObjs(Class<T> entityClass) {
  336. return listObjs(entityClass, i -> i);
  337. }
  338. /**
  339. * 根据 Wrapper 条件,查询全部记录
  340. *
  341. * @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
  342. */
  343. public static <T> List<Object> listObjs(AbstractWrapper<T, ?, ?> queryWrapper) {
  344. return SqlHelper.execute(getEntityClass(queryWrapper), baseMapper -> baseMapper.selectObjs(queryWrapper));
  345. }
  346. /**
  347. * 根据 Wrapper 条件,查询全部记录
  348. *
  349. * @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
  350. * @param mapper 转换函数
  351. */
  352. public static <T, V> List<V> listObjs(AbstractWrapper<T, ?, ?> queryWrapper, SFunction<? super T, V> mapper) {
  353. return SqlHelper.execute(getEntityClass(queryWrapper), baseMapper -> baseMapper.selectList(queryWrapper).stream().map(mapper).collect(Collectors.toList()));
  354. }
  355. /**
  356. * 查询全部记录
  357. *
  358. * @param entityClass 实体类
  359. * @param mapper 转换函数
  360. */
  361. public static <T, V> List<V> listObjs(Class<T> entityClass, SFunction<? super T, V> mapper) {
  362. return SqlHelper.execute(entityClass, baseMapper -> baseMapper.selectList(null).stream().map(mapper).collect(Collectors.toList()));
  363. }
  364. /**
  365. * 无条件翻页查询
  366. *
  367. * @param page 翻页对象
  368. * @param entityClass 实体类
  369. * @see Wrappers#emptyWrapper()
  370. */
  371. public static <T, E extends IPage<Map<String, Object>>> E pageMaps(E page, Class<T> entityClass) {
  372. return SqlHelper.execute(entityClass, baseMapper -> baseMapper.selectMapsPage(page, null));
  373. }
  374. /**
  375. * 翻页查询
  376. *
  377. * @param page 翻页对象
  378. * @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
  379. */
  380. public static <T, E extends IPage<Map<String, Object>>> E pageMaps(E page, AbstractWrapper<T, ?, ?> queryWrapper) {
  381. return SqlHelper.execute(getEntityClass(queryWrapper), baseMapper -> baseMapper.selectMapsPage(page, queryWrapper));
  382. }
  383. /**
  384. * 无条件翻页查询
  385. *
  386. * @param page 翻页对象
  387. * @param entityClass 实体类
  388. * @see Wrappers#emptyWrapper()
  389. */
  390. public static <T> IPage<T> page(IPage<T> page, Class<T> entityClass) {
  391. return SqlHelper.execute(entityClass, baseMapper -> baseMapper.selectPage(page, null));
  392. }
  393. /**
  394. * 翻页查询
  395. *
  396. * @param page 翻页对象
  397. * @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
  398. */
  399. public static <T> IPage<T> page(IPage<T> page, AbstractWrapper<T, ?, ?> queryWrapper) {
  400. return SqlHelper.execute(getEntityClass(queryWrapper), baseMapper -> baseMapper.selectPage(page, queryWrapper));
  401. }
  402. /**
  403. * 链式查询 普通
  404. *
  405. * @return QueryWrapper 的包装类
  406. */
  407. public static <T> QueryChainWrapper<T> query(Class<T> entityClass) {
  408. return ChainWrappers.queryChain(entityClass);
  409. }
  410. /**
  411. * 链式查询 lambda 式
  412. * <p>注意:不支持 Kotlin </p>
  413. *
  414. * @return LambdaQueryWrapper 的包装类
  415. */
  416. public static <T> LambdaQueryChainWrapper<T> lambdaQuery(Class<T> entityClass) {
  417. return ChainWrappers.lambdaQueryChain(entityClass);
  418. }
  419. /**
  420. * 链式更改 普通
  421. *
  422. * @return UpdateWrapper 的包装类
  423. */
  424. public static <T> UpdateChainWrapper<T> update(Class<T> entityClass) {
  425. return ChainWrappers.updateChain(entityClass);
  426. }
  427. /**
  428. * 链式更改 lambda 式
  429. * <p>注意:不支持 Kotlin </p>
  430. *
  431. * @return LambdaUpdateWrapper 的包装类
  432. */
  433. public static <T> LambdaUpdateChainWrapper<T> lambdaUpdate(Class<T> entityClass) {
  434. return ChainWrappers.lambdaUpdateChain(entityClass);
  435. }
  436. /**
  437. * <p>
  438. * 根据updateWrapper尝试更新,否继续执行saveOrUpdate(T)方法
  439. * 此次修改主要是减少了此项业务代码的代码量(存在性验证之后的saveOrUpdate操作)
  440. * </p>
  441. *
  442. * @param entity 实体对象
  443. */
  444. public static <T> boolean saveOrUpdate(T entity, AbstractWrapper<T, ?, ?> updateWrapper) {
  445. return update(entity, updateWrapper) || saveOrUpdate(entity);
  446. }
  447. /**
  448. * 根据 Wrapper,查询一条记录
  449. *
  450. * @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
  451. * @param mapper 转换函数
  452. */
  453. public static <T, V> V getObj(AbstractWrapper<T, ?, ?> queryWrapper, SFunction<? super T, V> mapper) {
  454. return SqlHelper.execute(getEntityClass(queryWrapper), baseMapper -> mapper.apply(baseMapper.selectOne(queryWrapper)));
  455. }
  456. /**
  457. * 从集合中获取实体类型
  458. *
  459. * @param entityList 实体集合
  460. * @param <T> 实体类型
  461. * @return 实体类型
  462. */
  463. @SuppressWarnings("unchecked")
  464. private static <T> Class<T> getEntityClass(Collection<T> entityList) {
  465. Class<T> entityClass = null;
  466. for (T entity : entityList) {
  467. if (entity != null && entity.getClass() != null) {
  468. entityClass = (Class<T>) entity.getClass();
  469. break;
  470. }
  471. }
  472. Assert.notNull(entityClass, "error: can not get entityClass from entityList");
  473. return entityClass;
  474. }
  475. /**
  476. * 从wrapper中尝试获取实体类型
  477. *
  478. * @param queryWrapper 条件构造器
  479. * @param <T> 实体类型
  480. * @return 实体类型
  481. */
  482. @SuppressWarnings("unchecked")
  483. private static <T> Class<T> getEntityClass(AbstractWrapper<T, ?, ?> queryWrapper) {
  484. Class<T> entityClass = queryWrapper.getEntityClass();
  485. if (entityClass == null) {
  486. T entity = queryWrapper.getEntity();
  487. if (entity != null) {
  488. entityClass = (Class<T>) entity.getClass();
  489. }
  490. }
  491. Assert.notNull(entityClass, "error: can not get entityClass from wrapper");
  492. return entityClass;
  493. }
  494. /**
  495. * 获取表信息,获取不到报错提示
  496. *
  497. * @param entityClass 实体类
  498. * @param <T> 实体类型
  499. * @return 对应表信息
  500. */
  501. private static <T> TableInfo getTableInfo(Class<T> entityClass) {
  502. return Optional.ofNullable(TableInfoHelper.getTableInfo(entityClass)).orElseThrow(() -> ExceptionUtils.mpe("error: can not find TableInfo from Class: \"%s\".", entityClass.getName()));
  503. }
  504. }