@JFinal 你好,想跟你请教个问题:
T_section section=new T_section(); String sectionId = ele.elementText("SectionId"); String sectionName = ele.elementText("SectionName"); section.set("sectionId", sectionId); section.set("sname", sectionName); section.set("hid", hid); section.save(); System.out.println("更新成功"); 错误信息是:
com.jfinal.plugin.activerecord.ActiveRecordException: com.jfinal.plugin.activerecord.ActiveRecordException: The attribute name does not exist: id at com.jfinal.plugin.activerecord.Model.save(Model.java:375) at com.qfkj.model.update.UpdateSectionForAll.saveSection(UpdateSectionForAll.java:89) at com.qfkj.controller.hospital.T_hospitalController.index(T_hospitalController.java:11) 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:601) at com.jfinal.aop.Invocation.invoke(Invocation.java:71) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:74) at com.jfinal.ext.handler.ContextPathHandler.handle(ContextPathHandler.java:47) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72) 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:503) 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:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:722) Caused by: com.jfinal.plugin.activerecord.ActiveRecordException: The attribute name does not exist: id at com.jfinal.plugin.activerecord.Model.set(Model.java:119) at com.jfinal.plugin.activerecord.Model.getGeneratedKey(Model.java:396) at com.jfinal.plugin.activerecord.Model.save(Model.java:371) ... 27 more
是因为我这个表的主键名不是id而是sid吗
你的主键没设置自增长吧!######设置了自增长的######Config中注册Model时,给出的ID名不正确######回复 @糊搞 :指定了主键名,但是出现列名“id” 无效我这里命名没有id这一列名啊######回复 @糊搞 : 是怎样指定呢,看手册没有,也没有百度到######回复 @翊为 : 默认为“id”,所以不是此名的话需要指定id字段名######arp.addMapping("T_section", T_section.class);这样是不是默认主键是id?###### 映射 model 的时候设置一下主键名即可:
arp.addMapping("T_section", "sid", T_section.class)
这个在手册的中的例子中都有说明。 ######回复 @糊搞 : 好的,谢谢######回复 @翊为 : 看手册一定要仔细呀,何况你还在这里出现了问题,更要仔细看了######后来在手册中看到了,可能是我以前看手册不够仔细,一直认为是在介绍config配置中但是其实是在5.2 5.2 ActiveRecordPlugin这一节
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。