AbstractLambdaWrapper 最終會調(diào)用 columnToString(SFunction<T, ?> column, boolean onlyColumn)
調(diào)用 getColumn(LambdaUtils.resolve(column), onlyColumn)
核心邏輯
Class<?> aClass = lambda.getInstantiatedType();
if (!initColumnMap) {
columnMap = LambdaUtils.getColumnMap(aClass);
initColumnMap = true;
}
Assert.notNull(columnMap, "can not find lambda cache for this entity [%s]", aClass.getName());
此時(shí) lambda 為 SFunction -> IndexQuoteCommon::getIfValid
aClass 為 IndexQuoteCommon(公共實(shí)體抽象類或者接口,因?yàn)槟阋槿」策壿嬍墙⒃诠驳淖侄紊系?
進(jìn)到 LambdaUtils.getColumnMap(aClass) 方法
return COLUMN_CACHE_MAP.computeIfAbsent(clazz.getName(), key -> {
TableInfo info = TableInfoHelper.getTableInfo(clazz);
return info == null ? null : createColumnCacheMap(info);
});
COLUMN_CACHE_MAP 是被標(biāo)記了 @TableName("xxx") 才會被緩存的表字段,而我們的抽象類IndexQuoteCommon 實(shí)際上是不在這個(gè)數(shù)據(jù)字典類的
最終報(bào)錯:can not find lambda cache for this entity [%s]
或者:com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: 該方法僅能傳入 lambda 表達(dá)式產(chǎn)生的合成類
注:TableInfo 是 mybatis 的對表描述的類
有沒方式解決呢?如果只從 lambda 角度去實(shí)現(xiàn),可能不太現(xiàn)實(shí)隘膘,因?yàn)槌橄箢惐仨氁患虞d到COLUMN_CACHE_MAP。
我們可以使用普通字符串 query 方式杠览,直接繞過 columnToString 方式