| public interface ISqlInjector { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void inspectInject(MapperBuilderAssistant builderAssistant, Class<?> mapperClass); |
| } |
- AbstractSqlInjector实现了ISqlInjector接口
| public abstract class AbstractSqlInjector implements ISqlInjector { |
| protected final Log logger = LogFactory.getLog(this.getClass()); |
| |
| public AbstractSqlInjector() { |
| } |
| |
| public void inspectInject(MapperBuilderAssistant builderAssistant, Class<?> mapperClass) { |
| Class<?> modelClass = ReflectionKit.getSuperClassGenericType(mapperClass, Mapper.class, 0); |
| if (modelClass != null) { |
| String className = mapperClass.toString(); |
| Set<String> mapperRegistryCache = GlobalConfigUtils.getMapperRegistryCache(builderAssistant.getConfiguration()); |
| if (!mapperRegistryCache.contains(className)) { |
| TableInfo tableInfo = TableInfoHelper.initTableInfo(builderAssistant, modelClass); |
| List<AbstractMethod> methodList = this.getMethodList(mapperClass, tableInfo); |
| if (CollectionUtils.isNotEmpty(methodList)) { |
| methodList.forEach((m) -> { |
| m.inject(builderAssistant, mapperClass, modelClass, tableInfo); |
| }); |
| } else { |
| this.logger.debug(mapperClass.toString() + ", No effective injection method was found."); |
| } |
| |
| mapperRegistryCache.add(className); |
| } |
| } |
| |
| } |
| |
| public abstract List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo); |
| } |
- DefaultSqlInjector继承了AbstractSqlInjector抽象类
| public class DefaultSqlInjector extends AbstractSqlInjector { |
| public DefaultSqlInjector() { |
| } |
| |
| public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) { |
| Builder<AbstractMethod> builder = Stream.builder().add(new Insert()).add(new Delete()).add(new DeleteByMap()).add(new Update()).add(new SelectByMap()).add(new SelectCount()).add(new SelectMaps()).add(new SelectMapsPage()).add(new SelectObjs()).add(new SelectList()).add(new SelectPage()); |
| if (tableInfo.havePK()) { |
| builder.add(new DeleteById()).add(new DeleteBatchByIds()).add(new UpdateById()).add(new SelectById()).add(new SelectBatchByIds()); |
| } else { |
| this.logger.warn(String.format("%s ,Not found @TableId annotation, Cannot use Mybatis-Plus 'xxById' Method.", tableInfo.getEntityType())); |
| } |
| |
| return (List)builder.build().collect(Collectors.toList()); |
| } |
| } |
| public class DeleteAll extends AbstractMethod { |
| |
| @Override |
| public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) { |
| |
| String sql = "delete from " + tableInfo.getTableName(); |
| |
| String method = "deleteAll"; |
| SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass); |
| return this.addDeleteMappedStatement(mapperClass, method, sqlSource); |
| } |
| } |
| public class MyLogicSqlInjector extends DefaultSqlInjector { |
| |
| |
| |
| |
| |
| |
| @Override |
| public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) { |
| List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo); |
| methodList.add(new DeleteAll()); |
| methodList.add(new MyInsertAll()); |
| methodList.add(new MysqlInsertAllBatch()); |
| methodList.add(new SelectById()); |
| return methodList; |
| } |
| } |
| public interface MyBaseMapper<T> extends BaseMapper<T> { |
| |
| |
| |
| |
| Integer deleteAll(); |
| |
| int myInsertAll(T entity); |
| |
| |
| |
| |
| |
| |
| |
| int mysqlInsertAllBatch(@Param("list") List<T> batchList); |
| } |
| @SpringBootTest |
| class DeluxeTest { |
| |
| @Resource |
| private UserMapper mapper; |
| |
| |
| |
| |
| |
| @Test |
| void testDelAll() { |
| mapper.deleteAll(); |
| } |
| |
| } |
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术