mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2026-08-18 17:21:06 +00:00
fix 修复 mapper.lambda 链式调用无法走 @DS 直接切换数据源问题
This commit is contained in:
+24
-2
@@ -6,7 +6,9 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.metadata.MapperProxyMetadata;
|
||||
import com.baomidou.mybatisplus.core.toolkit.reflect.GenericTypeUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.MybatisUtils;
|
||||
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.ChainWrappers;
|
||||
@@ -14,6 +16,7 @@ import com.baomidou.mybatisplus.extension.toolkit.Db;
|
||||
import org.apache.ibatis.logging.Log;
|
||||
import org.apache.ibatis.logging.LogFactory;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -100,7 +103,26 @@ public interface BaseMapperPlus<T, V> extends BaseMapper<T> {
|
||||
* @return Lambda CRUD 链式包装器
|
||||
*/
|
||||
default LambdaCrudChainWrapper<T, V> lambda() {
|
||||
return new LambdaCrudChainWrapper<>(this);
|
||||
return new LambdaCrudChainWrapper<>(mapperProxy());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前 Mapper 对应的 Spring 代理对象,确保 Mapper 上的切面注解能够继续生效。
|
||||
*
|
||||
* @return Mapper 代理对象
|
||||
*/
|
||||
private BaseMapperPlus<T, V> mapperProxy() {
|
||||
BaseMapperPlus<T, V> mapper = this;
|
||||
try {
|
||||
MapperProxyMetadata metadata = MybatisUtils.getMapperProxy(this);
|
||||
Object proxy = SpringUtils.getBean(metadata.getMapperInterface());
|
||||
if (proxy instanceof BaseMapperPlus<?, ?>) {
|
||||
mapper = (BaseMapperPlus<T, V>) proxy;
|
||||
}
|
||||
} catch (RuntimeException ignored) {
|
||||
// Mapper 可能未托管于 Spring 容器,保留当前对象作为回退。
|
||||
}
|
||||
return mapper;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +131,7 @@ public interface BaseMapperPlus<T, V> extends BaseMapper<T> {
|
||||
* @return Lambda 链式更新包装器
|
||||
*/
|
||||
default LambdaUpdateChainWrapper<T> lambdaUpdate() {
|
||||
return ChainWrappers.lambdaUpdateChain(this);
|
||||
return ChainWrappers.lambdaUpdateChain(mapperProxy());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user