jfinal 3.2 Template 在tomcat7下Record 通过obj.id无法获取去值

错误代码如下:jetty运行正常

com.jfinal.render.RenderException: com.jfinal.template.TemplateException: Field not found: "obj.first_name" and getter method not found: "obj.getFirst_name()"

Template: "/front/search_tabbar.html". Line: 40

at com.jfinal.render.TemplateRender.render(TemplateRender.java:63)

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

at com.javen.handler.BaseContextPathHandler.handle(BaseContextPathHandler.java:41)

at com.jfinal.ext.handler.ContextPathHandler.handle(ContextPathHandler.java:48)

at com.jfinal.plugin.druid.DruidStatViewHandler.handle(DruidStatViewHandler.java:75)

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

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:219)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)

at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Thread.java:745)

Caused by: com.jfinal.template.TemplateException: Field not found: "obj.first_name" and getter method not found: "obj.getFirst_name()"

Template: "/front/search_tabbar.html". Line: 40

at com.jfinal.template.expr.ast.Field.eval(Field.java:111)

at com.jfinal.template.expr.ast.ExprList.eval(ExprList.java:67)

at com.jfinal.template.stat.ast.Output.exec(Output.java:48)

at com.jfinal.template.stat.ast.StatList.exec(StatList.java:48)

at com.jfinal.template.stat.ast.For.forIterator(For.java:74)

at com.jfinal.template.stat.ast.For.exec(For.java:53)

at com.jfinal.template.stat.ast.StatList.exec(StatList.java:48)

at com.jfinal.template.Template.render(Template.java:49)

at com.jfinal.render.TemplateRender.render(TemplateRender.java:60)

... 22 more


评论区

杜福忠

2018-03-15 15:00

obj.get("first_name") 试试

JFinal

2018-03-15 16:13

异常已经很明确了: com.jfinal.render.RenderException: com.jfinal.template.TemplateException: Field not found: "obj.first_name" and getter method not found: "obj.getFirst_name()"

确认一下你的这个 obj 是不是 Record 类型,然后确认一下里头是不是有 "first_name" 字段

据判断,肯定是 obj 并非 Record 类型,因为 Record 类型取值时,即便是 "first_name" 不存在也不会报错

通过下面的方法可以看看 obj 到底是什么类型:
#(obj)

燕龙910

2018-03-16 10:38

@JFinal 错误是比较明显,就是感觉怪怪的,jetty可以tomcat就不能直接使用#(obj.first_name),没事已经解决了,谢谢,就是通过#(obj)看了下才知道的。

燕龙910

2018-03-16 10:39

@杜福忠 谢谢,已经成功拿到想要的值了

JFinal

2018-03-16 11:59

@燕龙910 啥原因呢? 说出来或许可以帮助到碰到同样问题的朋友

燕龙910

2018-03-21 13:45

@JFinal 惭愧,没有能查出直接原因,我还是用的是obj.get("first_name")取到值。

热门反馈

扫码入社