list数据:<#list persons as person>
${person.name}--${person.age}--${person.sex}<br/> </#list>页面已经生成,但是报错
freemarker.core.InvalidReferenceException: Expression persons is undefined on line 6, column 23 in WEB-INF/ftl/index.ftl.
freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124) freemarker.core.IteratorBlock.accept(IteratorBlock.java:100) freemarker.core.Environment.visit(Environment.java:210) freemarker.core.MixedContent.accept(MixedContent.java:92) freemarker.core.Environment.visit(Environment.java:210) freemarker.core.Environment.process(Environment.java:190) freemarker.template.Template.process(Template.java:237) org.apache.struts2.views.freemarker.FreemarkerResult.doExecute(FreemarkerResult.java:202) org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186) com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)解决办法: 这是因为模板里要输出的对象是空的,所以报错.解决办法就是在输出之前判断下就可以了
list数据:
<#if persons ??>
<#list persons as person>
${person.name}--${person.age}--${person.sex}<br/> </#list></#if>