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)
解決思路:
百度了一下,這樣的錯誤不是太多,多是不多人用的緣由吧。
一、首先,我修改了數據庫鏈接方式,
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,測試了一下數據庫鏈接方式沒有錯。
二、有說本身寫一個bean的,我想都沒想,pass了,jFinal就是不須要本身寫bean的。
三、後來仔細找代碼的錯誤,發現了,沒有加這行
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);
四、因而,我把須要傳對象的頁面的屬性都稍做修改,加上user. 這回就行了,一個小小的錯誤,百度了好久,都是粗心惹的禍。 下回注意。