jFinal中报对应模型不存在的错误(The Table mapping of model: demo.User not exists)

时间:2024-08-23 22:36:38
jFinal中报对应模型不存在的错误(The Table mapping of model: demo.User not exists)

贴出错误:
java.lang.RuntimeException: The Table mapping of model: demo.User not exists. Please add mapping to ActiveRecordPlugin: activeRecordPlugin.addMapping(tableName, YourModel.class).
at com.jfinal.plugin.activerecord.TableMapping.getTable(TableMapping.java:45)
at com.jfinal.core.ModelInjector.injectActiveRecordModel(ModelInjector.java:83)
at com.jfinal.core.ModelInjector.inject(ModelInjector.java:50)
at com.jfinal.core.ModelInjector.inject(ModelInjector.java:37)
at com.jfinal.core.Controller.getModel(Controller.java:625)
at demo.UserController.add(UserController.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.jfinal.core.ActionInvocation.invoke(ActionInvocation.java:55)
at com.jfinal.core.ActionHandler.handle(ActionHandler.java:73)
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:744)

解决思路:

百度了一下,这样的错误不是太多,可能是很少人用的原因吧。

1、首先,我修改了数据库连接方式,

C3p0Plugin cp = new C3p0Plugin("jdbc:mysql://localhost:3306/jfinal","root", "a");
me.add(cp);
ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
arp.addMapping("user", User.class);

但是还报这个错,我想可能是连接数据库的url什么的错了,于是,写了一个简单的demo,测试了一下数据库连接方式没有错。

2、有说自己写一个bean的,我想都没想,pass了,jFinal就是不需要自己写bean的。

3、后来仔细找代码的错误,发现了,没有加这行 

   me.add(cp);

于是加上,想这回应该可以了吧,可还是报错。

C3p0Plugin cp = new C3p0Plugin("jdbc:mysql://localhost:3306/jfinal","root", "a");
me.add(cp);
ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
me.add(arp);
arp.addMapping("user", User.class);

4、于是,我把需要传对象的页面的属性都稍作修改,加上user. 

这回就好了,一个小小的错误,百度了很久,都是粗心惹的祸。

下回注意。