确认

  • [X] 我使用的版本是最新版, 并且使用插件确认过项目里无依赖版本冲突
  • [X] 我已经在 issue 中搜索过, 确认问题没有被提出过
  • [X] 我已经修改标题, 将标题中的 描述 替换为遇到的问题

当前程序版本

3.5.7

问题描述

运行时报错代码

// 通用的检查方法
    private <T> void checkEntityExists(Object entityId, String entityName, BaseMapper<T> entityMapper) {
        try {
            // 获取实体类类型
            Class<?>[] classes = GenericTypeUtils.resolveTypeArguments(entityMapper.getClass(), BaseMapper.class);
            Class<T> entityClass = (Class<T>) classes[0];
            // 通过反射获取实体类的 getId 方法
            Method getIdMethod = entityClass.getMethod("getId");

            // 使用lambdaQuery查询记录是否存在
            boolean exists = entityMapper.exists(Wrappers.<T>lambdaQuery()
                .eq(new SFunction<T, Long>() {
                    @Override
                    public Long apply(T t) {
                        try {
                            return (Long) getIdMethod.invoke(t);
                        } catch (IllegalAccessException e) {
                            throw new RuntimeException(e);
                        } catch (InvocationTargetException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }, entityId)
            );
            if (!exists) {
                throw new RuntimeException("错误的id");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
错误信息:

Error evaluating expression 'ew.sqlSegment != null and ew.sqlSegment != '''. Cause: org.apache.ibatis.ognl.OgnlException: sqlSegment [com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: java.io.NotSerializableException: org.example.test.MyTest]

我按照#4777这个方法修改后可以了,我直接new SFunction() 有什么问题吗

详细堆栈日志

Error evaluating expression 'ew.sqlSegment != null and ew.sqlSegment != '''. Cause: org.apache.ibatis.ognl.OgnlException: sqlSegment [com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: java.io.NotSerializableException: org.example.test.MyTest]

Comment From: miemieYaho

不支持