我的环境,jdk1.8.0.202,jfinal3.5.
使用代码:
String pk = object.getPk(); String pkValue = record.get(pk).toString(); // 删除数据 Db.use(object.getDs()).delete(object.getTable(), pk, record);
到这一行就报错了:
java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object; at com.jfinal.plugin.activerecord.DbPro.delete(DbPro.java:461) at com.eova.widget.grid.GridController$2.run(GridController.java:282) at com.jfinal.plugin.activerecord.DbPro.tx(DbPro.java:770) at com.jfinal.plugin.activerecord.DbPro.tx(DbPro.java:807) at com.eova.widget.grid.GridController.deleteOrHide(GridController.java:260) at com.eova.widget.grid.GridController.delete(GridController.java:236) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.jfinal.aop.Invocation.invoke(Invocation.java:75) at com.eova.interceptor.AuthInterceptor.intercept(AuthInterceptor.java:71) at com.jfinal.aop.Invocation.invoke(Invocation.java:69) at com.eova.interceptor.LoginInterceptor.intercept(LoginInterceptor.java:81) at com.jfinal.aop.Invocation.invoke(Invocation.java:69) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:81) at com.jfinal.ext.handler.UrlSkipHandler.handle(UrlSkipHandler.java:46) at com.jfinal.ext.handler.UrlSkipHandler.handle(UrlSkipHandler.java:46) at com.jfinal.plugin.druid.DruidStatViewHandler.handle(DruidStatViewHandler.java:81) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:86) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2522) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2511) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)
请教一下原因。
另外,这些代码之前是在jdk1.7环境下使用的,一直没有问题,最近把jdk升级到1.8之后才出现的上述问题。
目前建议的解决办法如下:
1:改用 deleteById,例如:Db.deleteById("user", "id", record.getInt("id"));
2:使用线上最新版本: git@gitee.com:jfinal/jfinal.git
线上最新版本使用下面的办法安装到本地:
git clone git@gitee.com:jfinal/jfinal.git
cd jfinal
mvn clean install
安装完成后,项目中的 3.5 版本号改成 3.6-SNAPSHOT
以上两个办法,两者选其一就可以。
Db 工具类中有很多可选方法可以使用,有两个方法会由 JDK 1.8 产生问题,换成别的方法代替就可以解决了。
过几天会发布 jfinal 3.6