FreeMarker template error

简介:

在使用freemarker的过程中经常会见到如下错误:

Xml代码   收藏代码
  1. 11 十二月 2015 15:53:09,674 ERROR freemarker.runtime:98 - Error executing FreeMarker template  
  2. FreeMarker template error:  
  3. The following has evaluated to null or missing:  
  4. ==> sex  [in template "freemarker3.html" at line 10, column 3]  
  5.   
  6. Tip: If the failing expression is known to be legally null/missing, either specify a default value with myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthessis: (myOptionVar.foo)!myDefault, (myOptionVar.foo)??  

模板代码如下:

Html代码   收藏代码
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <meta charset="UTF-8">  
  5. <title>freemarker demo</title>  
  6. </head>  
  7. <body>  
  8. ${username} <br />  
  9. ${age}<br />  
  10. ${sex}  
  11. </body>  
  12. </html>  

 根本原因: sex没有设置值,所以报错

解决方法:

在未声明的变量后面增加叹号

Html代码   收藏代码
  1. ${sex!}  

 也可以设置默认值,在叹号后面增加默认值

Html代码   收藏代码
  1. ${sex!'abc'}  

  

相关文章
|
3天前
An error happened during template parsing (template: “ServletContext resource [/WEB-INF/templates/in
An error happened during template parsing (template: “ServletContext resource [/WEB-INF/templates/in
|
3天前
|
Java Spring
spring-doc报错Unable to render this definition
spring-doc报错Unable to render this definition
188 0
|
9月前
|
存储 应用服务中间件
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template
|
11月前
报错 An error happened during template parsing (template: “ServletContext resource [/shiroTest.html]“)
报错 An error happened during template parsing (template: “ServletContext resource [/shiroTest.html]“)
|
11月前
|
存储 编译器 C++
【C++模板】——template
【C++模板】——template
|
Java 测试技术 Spring
Configuration problem: Failed to import bean definitions from URL location classpath:spring-mvc.xml
Configuration problem: Failed to import bean definitions from URL location classpath:spring-mvc.xml
643 0
|
存储 小程序
【小程序】自定义组件的data、methods、properties
【小程序】自定义组件的data、methods、properties
304 0
【小程序】自定义组件的data、methods、properties
|
JavaScript
vue element-ui [Vue warn]: Invalid prop: custom validator check failed for prop “index“.
vue element-ui [Vue warn]: Invalid prop: custom validator check failed for prop “index“.
270 0
vue element-ui [Vue warn]: Invalid prop: custom validator check failed for prop “index“.
|
前端开发
九十八、freemarker框架报错 s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request
九十八、freemarker框架报错 s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request
1069 0
九十八、freemarker框架报错 s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request
cannot bind to cxOutlet since it is not a known property of ng template
cannot bind to cxOutlet since it is not a known property of ng template
94 0
cannot bind to cxOutlet since it is not a known property of ng template