MybatisPlus的使用?能否在父类使用子类泛型中的方法引用?
场景是这样的,我不知道该如何描述问题:
我有一部分持久化实体继承了父类,有一些公用属性。
我想在业务类基类里提供一个公用查询方法,入参使用公用属性。
所以在业务类基类里写了以下代码:
public List<T> getListByPmId(String pmId) {
LambdaQueryWrapper<T> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(T::getPmId, pmId);
return this.getMapper().selectList(queryWrapper);
}
实际运行时,MybatisPlus抛出了以下异常
com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this entity [com.xxx.common.base.entity.BaseEntity]
换成这种写法也是一样的
public List<T> getListByPmId(String pmId) {
return this.getMapper().selectList(Wrappers.<T>lambdaQuery()
.eq(T::getPmId, pmId));
}
用字符串参数的QueryWrapper肯定是正常的,我已经这样写了。
但是LambdaQueryWrapper这里应该如何理解?
感觉也不是单纯的类型擦除导致的,如果用getClass().getTypeParameters()[0]取到子类泛型后应该如何拿到对应方法的Function呢?
能否避免反射实现呢?