nore * @return ignore */ @Transactional(rollbackFor = Exception.class) @Override public boolean saveBatch(Collection entityList, int batchSize) { String sqlStatement = getSqlStatement(SqlMethod.INSERT_ONE); return executeBatch(entityList, batchSize, (sqlSession, entity) -> sqlSession.insert(sqlStatement, entity)); } /** * 提供mapperStatementId * * @param sqlMethod 法则名 * @return 定名为id * @since 3.4.0 */ protected String getSqlStatement(SqlMethod sqlMethod) { return SqlHelper.getSqlStatement(mapperClass, sqlMethod); } /** * TableId 注解存在更新历史纪录,究竟抽出一条历史纪录 * * @param entity 对等取向 * @return boolean */ @Transactional(rollbackFor = Exception.class) @Override public boolean saveOrUpdate(T entity) { if (null != entity) { TableInfo tableInfo = TableInfoHelper.getTableInfo(this.entityClass); Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!"); String keyProperty = tableInfo.getKeyProperty(); Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!"); Object idVal = ReflectionKit.getFieldValue(entity, tableInfo.getKeyProperty()); return StringUtils.checkValNull(idVal) || Objects.isNull(getById((Serializable) idVal)) ? save(entity) : updateById(entity); } return false; } @Transactional(rollbackFor = Exception.class) @Override public boolean saveOrUpdateBatch(Collection entityList, int batchSize) { TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass); Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!"); String keyProperty = tableInfo.getKeyProperty(); Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!"); return SqlHelper.saveOrUpdateBatch(this.entityClass, this.mapperClass, this.log, entityList, batchSize, (sqlSession, entity) -> { Object idVal = ReflectionKit.getFieldValue(entity, keyProperty); return StringUtils.checkValNull(idVal) || CollectionUtils.isEmpty(sqlSession.selectList(getSqlStatement(SqlMethod.SELECT_BY_ID), entity)); }, (sqlSession, entity) -> { MapperMethod.ParamMap param = new MapperMethod.ParamMap<>(); param.put(Constants.ENTITY, entity); sqlSession.update(getSqlStatement(SqlMethod.UPDATE_BY_ID), param); }); } @Transactional(rollbackFor = Exception.class) @Override public boolean updateBatchById(Collection entityList, int batchSize) { String sqlStatement = getSqlStatement(SqlMethod.UPDATE_BY_ID); return executeBatch(entityList, batchSize, (sqlSession, entity) -> { MapperMethod.ParamMap param = new MapperMethod.ParamMap<>(); param.put(Constants.ENTITY, entity); sqlSession.update(sqlStatement, param); }); } @Override public T getOne(Wrapper queryWrapper, boolean throwEx) { if (throwEx) { return baseMapper.selectOne(queryWrapper); } return SqlHelper.getObject(log, baseMapper.selectList(queryWrapper)); } @Override public Map getMap(Wrapper queryWrapper) { return SqlHelper.getObject(log, baseMapper.selectMaps(queryWrapper)); } @Override public V getObj(Wrapper queryWrapper, Function mapper) { return SqlHelper.getObject(log, listObjs(queryWrapper, mapper)); } /** * 执行低成本操控 * * @param consumer consumer * @since 3.3.0 * @deprecated 3.3.1 前面我打算移杀掉 {@link #executeBatch(Collection, int, BiConsumer)} }. */ @Deprecated protected boolean executeBatch(Consumer consumer) { return SqlHelper.executeBatch(this.entityClass, this.log, consumer); } /** * 执行低成本操控 * * @param list 数据等价 * @param batchSize 低成本大小 * @param consumer 执行法则 * @param 泛型 * @return 操控结果 * @since 3.3.1 */ protected boolean executeBatch(Collection list, int batchSize, BiConsumer consumer) { return SqlHelper.executeBatch(this.entityClass, this.log, list, batchSize, consumer); } /** * 执行低成本操控(默认批次提交数量{@link IService#DEFAULT_BATCH_SIZE}) * * @param list 数据等价 * @param consumer 执行法则 * @param 泛型 * @return 操控结果 * @since 3.3.1 */ protected boolean executeBatch(Collection list, BiConsumer consumer) { return executeBatch(list, DEFAULT_BATCH_SIZE, consumer); }}ServiceImpl类各法则(未已确定)的关键作用
1.getBaseMapper()2.getEntityClass()3.saveBatch()4.saveOrUpdate()5.saveOrUpdateBatch()6.updateBatchById()7.getOne()8.getMap()9.getObj()
ServiceImpl类各类型的关键作用
1.log:打印日志2.baseMapper:借助于了许多的SQL操控3.entityClass:对等类4.mapperClass:映射类
BaseMapper类中各法则
ServiceImpl类中有这个类的的组织变量,因此通过ServiceImpl这个类便很难操控如下法则:
1.int insert(T entity);:抽出历史纪录2.int deleteById(Serializable id);:通过id写入选定历史纪录3.int deleteByMap(Map columnMap):通过Map等价添加写入选定历史纪录4.int delete(@Param(Constants.WRAPPER) Wrapper queryWrapper):通过添加特征机写入选定历史纪录5.int deleteBatchIds(Collection idList):通过List等价低成本写入历史纪录
6.int updateById(T entity):根据id修改选定历史纪录7.int update(T entity, Wrapper updateWrapper):根据必须特征机8.T selectById(Serializable id):根据id核对选定历史纪录9.List selectBatchIds(Collection idList):根据List等价低成本核对历史纪录10.List selectByMap(Map columnMap):根据Map等价核对历史纪录
11.T selectOne(Wrapper queryWrapper):根据必须特征机核对一条历史纪录12.Integer selectCount(Wrapper queryWrapper):根据必须特征机核对历史纪录总数13.List selectList(Wrapper queryWrapper):根据必须特征机核对全部历史纪录14.List
Wrapper类各法则
1.getEntity():对等取向(类别借助于)2.getSqlSelectgetSqlSet():3.getSqlComment():4.getSqlFirst():5.getExpression():提供 MergeSegments6.getCustomSqlSegment():提供快捷键SQL 一般化快捷键XML复杂持续性7.isEmptyOfWhere():核对必须为自造(还包括entity)8.nonEmptyOfWhere():核对必须不为自造(还包括entity)9.isEmptyOfNormal():核对必须为自造(不还包括entity)10.nonEmptyOfNormal():核对必须为自造(不还包括entity)11.nonEmptyOfEntity():深层对等辨别类型12.fieldStrategyMatch():根据对等FieldStrategy类型来不得不辨别直觉13.isEmptyOfEntity():深层对等辨别类型14.getTargetSql():提供格式化后的执行sql15.clear():必须清自造
重构说明
public class ServiceImpl
implements IService {}public class CategoryServiceImpl extends ServiceImpl implements CategoryService {}在ServiceImpl中已经汇流了Mapper取向: protected M baseMapper;因此XXXServiceImpl只要让位了这个原生的ServiceImpl,这个M对等Dao就已经汇流了全都,不只能重新汇流。
。重庆白癜风治疗方法有什么
盐城看白癜风去哪家医院好
北京妇科检查哪家医院好
兰州白癜风医院哪里最好
长沙看牛皮癣到哪家好