// remove(new QueryWrapper<Follow>()
// .eq("user_id", userId).eq("follow_user_id", followUserId));
remove(new LambdaQueryWrapper<Follow>().eq(Follow::getUserId, userId)
.eq(Follow::getFollowUserId, followUserId));
// Integer count = query().eq("user_id", userId).eq("follow_user_id", followUserId).count();
Integer count = lambdaQuery().eq(Follow::getUserId, userId).eq(Follow::getFollowUserId, followUserId).count();
两段代码都是,一用lambda表达式就报错
1.报错
mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'ew.sqlSegment != null and ew.sqlSegment != '' and ew.nonEmptyOfWhere'. Cause: org.apache.ibatis.ognl.OgnlException: sqlSegment [java.lang.NoClassDefFoundError: Could not initialize class com.baomidou.mybatisplus.core.toolkit.support.SerializedLambdaMeta]
Caused by: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'ew.sqlSegment != null and ew.sqlSegment != '' and ew.nonEmptyOfWhere'. Cause: org.apache.ibatis.ognl.OgnlException: sqlSegment [java.lang.NoClassDefFoundError: Could not initialize class com.baomidou.mybatisplus.core.toolkit.support.SerializedLambdaMeta]
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.baomidou.mybatisplus.core.toolkit.support.SerializedLambdaMeta
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.lang.Class java.lang.invoke.SerializedLambda.capturingClass accessible: module java.base does not "opens java.lang.invoke" to unnamed module @7ec7ffd3 [in thread "http-nio-8081-exec-6"]
2.原因
这个错误是由于Java 9及以上版本的模块化系统导致的。在Java 9中,Java语言引入了模块化系统,对Java平台和API进行了重新组织和划分,将Java代码划分为一系列模块,每个模块都有自己的命名空间和可见性。在模块化系统中,访问限制更加严格,如果要访问模块中的受保护的类、方法或字段,需要在模块声明中明确指定。
代码中使用了反射来访问一个私有的final字段,但是这个字段所在的模块没有向当前模块开放访问权限。具体来说,这个错误是由于SerializedLambda类中的一个私有final字段capturingClass引起的,这个字段表示捕获对象的类。在Java 9及以上版本中,SerializedLambda类被划分到了java.base模块中,而当前模块没有被授权访问java.base模块中的SerializedLambda类。
3.解决方法
写入
--add-opens java.base/java.lang.invoke=ALL-UNNAMED
这会临时开放java.lang.invoke模块给所有未命名模块(即非模块化的代码),允许反射访问。
后面遇到的另一个:
module java.base does not "opens java.lang" to unnamed module
这个错误是由于Java 9及以上版本的模块化系统引入的限制。在Java 9之前,Java类加载器可以加载任何类,但是Java 9引入了模块化系统,限制了类加载器的访问权限。在新的模块化系统中,类加载器无法访问未在模块声明中明确打开的包
--add-opens=java.base/java.lang=ALL-UNNAMED