From 8b07c9f665d53a7d96037874b8bdc11846e45953 Mon Sep 17 00:00:00 2001 From: f00lish Date: Sun, 20 Jun 2021 09:58:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0mybatis-plus=E5=88=B03.4.3.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../integration-mybatis-plugin1/pom.xml | 2 +- .../integration-mybatisplus-main/pom.xml | 2 +- .../pom.xml | 2 +- .../mybatisplus/ServiceImplWrapper.java | 146 +----------------- 4 files changed, 5 insertions(+), 147 deletions(-) diff --git a/example/integration-mybatis/plugins/integration-mybatis-plugin1/pom.xml b/example/integration-mybatis/plugins/integration-mybatis-plugin1/pom.xml index 4ab5fe7..3f2f0d4 100644 --- a/example/integration-mybatis/plugins/integration-mybatis-plugin1/pom.xml +++ b/example/integration-mybatis/plugins/integration-mybatis-plugin1/pom.xml @@ -17,7 +17,7 @@ jar - 3.4.1 + 3.4.3.1 2.2 2.0.1 diff --git a/example/integration-mybatisplus/integration-mybatisplus-main/pom.xml b/example/integration-mybatisplus/integration-mybatisplus-main/pom.xml index f72791f..aff0014 100644 --- a/example/integration-mybatisplus/integration-mybatisplus-main/pom.xml +++ b/example/integration-mybatisplus/integration-mybatisplus-main/pom.xml @@ -25,7 +25,7 @@ 3.7.0 2.0.1 - 3.4.1 + 3.4.3.1 2.4.3-RELEASE 2.4.3-RELEASE diff --git a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/pom.xml b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/pom.xml index b5229c0..8420141 100644 --- a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/pom.xml +++ b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/pom.xml @@ -66,7 +66,7 @@ 2.4.3-RELEASE 2.0.1 - 3.4.1 + 3.4.3.1 2.1.5 diff --git a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/mybatisplus/ServiceImplWrapper.java b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/mybatisplus/ServiceImplWrapper.java index 8b5414a..e7f53c9 100644 --- a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/mybatisplus/ServiceImplWrapper.java +++ b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/mybatisplus/ServiceImplWrapper.java @@ -1,161 +1,19 @@ package com.gitee.starblues.extension.mybatis.mybatisplus; -import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import java.io.Serializable; -import java.lang.reflect.Field; -import java.util.Collection; -import java.util.List; -import java.util.Map; import java.util.Objects; -import java.util.function.Function; /** * mybatis plus ServiceImpl 的包装。解决原生mybatis plus 中ServiceImpl Mapper无法注入的问题 - * 升级mybatis-plus到3.4.1 + * 升级mybatis-plus到3.4.3.1 * @author starBlues * @version 2.4.0 */ -public class ServiceImplWrapper, T> implements IService { - - private final ServiceImpl serviceImpl; - - protected M baseMapper; - +public class ServiceImplWrapper, T> extends ServiceImpl { public ServiceImplWrapper(M baseMapper) { this.baseMapper = Objects.requireNonNull(baseMapper); - this.serviceImpl = new ServiceImpl(); - setMapper(); - } - - /** - * 给ServiceImpl设置Mapper - */ - private void setMapper(){ - Class aClass = serviceImpl.getClass(); - Field[] fields = aClass.getDeclaredFields(); - for (Field field : fields) { - if(Objects.equals(field.getName(), "baseMapper") - || (baseMapper != null && baseMapper.getClass() == field.getType())){ - field.setAccessible(true); - try { - field.set(serviceImpl, baseMapper); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - } - } - - - @Override - public boolean save(T entity) { - return serviceImpl.save(entity); - } - - @Override - public boolean saveBatch(Collection entityList, int batchSize) { - return serviceImpl.saveBatch(entityList, batchSize); - } - - @Override - public boolean saveOrUpdateBatch(Collection entityList, int batchSize) { - return serviceImpl.saveOrUpdateBatch(entityList, batchSize); - } - - @Override - public boolean removeById(Serializable id) { - return serviceImpl.removeById(id); - } - - @Override - public boolean removeByMap(Map columnMap) { - return serviceImpl.removeByMap(columnMap); - } - - @Override - public boolean remove(Wrapper queryWrapper) { - return serviceImpl.remove(queryWrapper); - } - - @Override - public boolean removeByIds(Collection idList) { - return serviceImpl.removeByIds(idList); - } - - @Override - public boolean updateById(T entity) { - return serviceImpl.updateById(entity); - } - - @Override - public boolean update(T entity, Wrapper updateWrapper) { - return serviceImpl.update(entity, updateWrapper); - } - - @Override - public boolean updateBatchById(Collection entityList, int batchSize) { - return serviceImpl.updateBatchById(entityList, batchSize); - } - - @Override - public boolean saveOrUpdate(T entity) { - return serviceImpl.saveOrUpdate(entity); - } - - @Override - public T getById(Serializable id) { - return serviceImpl.getById(id); - } - - @Override - public T getOne(Wrapper queryWrapper, boolean throwEx) { - return serviceImpl.getOne(queryWrapper, throwEx); - } - - @Override - public Map getMap(Wrapper queryWrapper) { - return serviceImpl.getMap(queryWrapper); - } - - @Override - public V getObj(Wrapper queryWrapper, Function mapper) { - return serviceImpl.getObj(queryWrapper, mapper); - } - - @Override - public int count(Wrapper queryWrapper) { - return serviceImpl.count(queryWrapper); } - - @Override - public List list(Wrapper queryWrapper) { - return serviceImpl.list(queryWrapper); - } - - - @Override - public List> listMaps(Wrapper queryWrapper) { - return serviceImpl.listMaps(queryWrapper); - } - - @Override - public List listObjs(Wrapper queryWrapper, Function mapper) { - return serviceImpl.listObjs(queryWrapper, mapper); - } - - @Override - public M getBaseMapper() { - return this.baseMapper; - } - - @Override - public Class getEntityClass() { - return serviceImpl.getEntityClass(); - } - } -- Gitee