fingbyid报错

public int editprovinceinfoservice(Record record) {

// try {

if(record !=null) {

//通过id获取当前省份信息是否存在

Record red=Db.findById("provinceinfo", "provinceinfo_id", record.getInt("provinceinfo_id"));

if(red!=null) {

red.set("provinceinfo_name", record.getStr("provinceinfo_name"));

red.set("provinceinfo_note", record.getStr("provinceinfo_note"));

Db.update("provinceinfo", red);//更新数据

return 1;

}

return 2;

}

// }catch(Exception e) {

// System.err.println("service编辑省份数据记录异常");

// }

return 0;

}

=====================================

2019-03-27 15:13:53

[ERROR]-[Thread: XNIO-1 task-1]-[com.jfinal.core.ActionHandler.handle()]: /aprovinceinfo/editprovinceinfo?provinceinfo_id=120029&provinceinfo_name=tbxzq&provinceinfo_note=45645

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

at com.jfinal.aop.Invocation.invoke(Invocation.java:87)

at com.jfinal.core.ActionHandler.handle(ActionHandler.java:74)

at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:74)

at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)

at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)

at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)

at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)

at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)

at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)

at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)

at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)

at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)

at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)

at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)

at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)

at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)

at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

at io.undertow.servlet.handlers.SessionRestoringHandler.handleRequest(SessionRestoringHandler.java:119)

at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)

at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)

at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)

at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)

at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)

at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)

at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)

at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)

at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)

at io.undertow.server.Connectors.executeRootHandler(Connectors.java:364)

at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.reflect.InvocationTargetException

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.jfinal.aop.Invocation.invoke(Invocation.java:73)

... 33 more

Caused by: java.lang.NoSuchMethodError: com.jfinal.plugin.activerecord.Db.findById(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)Lcom/jfinal/plugin/activerecord/Record;

at com.haifeng.service.ProvinceInfoService.editprovinceinfoservice(ProvinceInfoService.java:73)

at com.haifeng.controller.ProvinceinfoController.editprovinceinfo(ProvinceinfoController.java:83)

... 38 more

====================================

评论区

JFinal

2019-03-28 09:44

异常核心信息:
Caused by: java.lang.NoSuchMethodError: com.jfinal.plugin.activerecord.Db.findById(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)

解决办法是:一是升级 jfinal 到最新版本, 二是将最后一个参数强制转化成 Object,或引入一个中间变量。

如果不想升级 jfinal 解决办法如下:
Db.findById("provinceinfo", "provinceinfo_id", (Object)record.getInt("provinceinfo_id"));

或者:
Object para = record.getInt("provinceinfo_id");
Db.findById("provinceinfo", "provinceinfo_id", para);

这个问题是由 JDK 8 引发的与 jfinal 无关。而 jfinal 新版本通过调整 findByIds 解决了这个问题

热门分享

扫码入社