freemarker错误九

1、错误叙述性说明

五月 30, 2014 11:52:04 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error
严重: Template processing error: "Can't convert the date to string, because it is not known which parts of the date variable are in use. Use ?date, ?time or ?datetime built-in, or ?string.\u003Cformat> or ?string(format) built-in with this date."

Can't convert the date to string, because it is not known which parts of the date variable are in use. Use ?

date, ?time or ?datetime built-in, or ?

string.<format> or ?string(format) built-in with this date.
The problematic instruction:
----------
==> ${nowsday} [on line 23, column 6 in type.ftl]
----------

Java backtrace for programmers:
----------
freemarker.template.TemplateModelException: Can't convert the date to string, because it is not known which parts of the date variable are in use. Use ?date, ?

time or ?datetime built-in, or ?string.<format> or ?string(format) built-in with this date.
	at freemarker.core.Environment.formatDate(Environment.java:776)
	at freemarker.core.Expression.getStringValue(Expression.java:105)
	at freemarker.core.Expression.getStringValue(Expression.java:93)
	at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
	at freemarker.core.Environment.visit(Environment.java:221)
	at freemarker.core.MixedContent.accept(MixedContent.java:92)
	at freemarker.core.Environment.visit(Environment.java:221)
	at freemarker.core.Environment.process(Environment.java:199)
	at freemarker.template.Template.process(Template.java:259)
	at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
	at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:173)
	at com.you.test.freemarker.FreemarkerTest.testDataType(FreemarkerTest.java:160)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>freemarker基本数据类型</title>

  </head>

  <body>
          张三丰

     123,456

     true
     false

Can't convert the date to string, because it is not known which parts of the date variable are in use. Use ?

date, ?

time or ?

datetime built-in, or ?

string.<format> or ?string(format) built-in with this date.
The problematic instruction:
----------
==> ${nowsday} [on line 23, column 6 in type.ftl]
----------

Java backtrace for programmers:
----------
freemarker.template.TemplateModelException: Can't convert the date to string, because it is not known which parts of the date variable are in use. Use ?

date, ?

time or ?datetime built-in, or ?string.<format> or ?string(format) built-in with this date.
	at freemarker.core.Environment.formatDate(Environment.java:776)
	at freemarker.core.Expression.getStringValue(Expression.java:105)
	at freemarker.core.Expression.getStringValue(Expression.java:93)
	at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
	at freemarker.core.Environment.visit(Environment.java:221)
	at freemarker.core.MixedContent.accept(MixedContent.java:92)
	at freemarker.core.Environment.visit(Environment.java:221)
	at freemarker.core.Environment.process(Environment.java:199)
	at freemarker.template.Template.process(Template.java:259)
	at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
	at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:173)
	at com.you.test.freemarker.FreemarkerTest.testDataType(FreemarkerTest.java:160)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Can't convert the date to string, because it is not known which parts of the date variable are in use. Use ?date, ?

time or ?datetime built-in, or ?string.<format> or ?string(format) built-in with this date.
The problematic instruction:
----------
==> ${nowsday} [on line 23, column 6 in type.ftl]
----------

Java backtrace for programmers:
----------
freemarker.template.TemplateModelException: Can't convert the date to string, because it is not known which parts of the date variable are in use. Use ?

date, ?time or ?

datetime built-in, or ?string.<format> or ?string(format) built-in with this date.
	at freemarker.core.Environment.formatDate(Environment.java:776)
	at freemarker.core.Expression.getStringValue(Expression.java:105)
	at freemarker.core.Expression.getStringValue(Expression.java:93)
	at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
	at freemarker.core.Environment.visit(Environment.java:221)
	at freemarker.core.MixedContent.accept(MixedContent.java:92)
	at freemarker.core.Environment.visit(Environment.java:221)
	at freemarker.core.Environment.process(Environment.java:199)
	at freemarker.template.Template.process(Template.java:259)
	at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
	at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:173)
	at com.you.test.freemarker.FreemarkerTest.testDataType(FreemarkerTest.java:160)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

2、错误原因

/**
	 * freemarker基本数据类型
	 * @Title:testDataType
	 * @Description:
	 * @param:
	 * @return: void
	 * @throws
	 */
	@Test
	public void testDataType()
	{
		root.put("nowsday", new Date());
		studentPrint("type.ftl");
	}

${nowsday}

不能将日期类型直接转换为字符串。由于不知道是日期类型中的哪一种在使用。是date、time还是datetime。而且不知道转换成字符串日期究竟显示成什么格式,是yyyy-MM-dd。还是HH:mm:ss,还是yyyy-MM-dd HH:mm:ss

3、解决的方法

 <#--日期类型-->
${nowsday?string("yyyy-MM-dd")}

结果:2014-05-31

版权声明:本文博客原创文章,博客,未经同意,不得转载。

时间: 2024-10-28 15:40:07

freemarker错误九的相关文章

spring错误汇总

在学习spring过程中遇见了种种不同的异常错误,这里做了一下总结,希望遇见类似错误的同学们共勉一下. 1. 错误一 Error creating bean with name 'helloServiceImpl' defined in class path resource [spring-service.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritableP

(转)ubuntu源码编译安装php常见错误解决办法

原文地址 http://blog.csdn.net/white__cat/article/details/28907535 './configure' '–prefix=/usr/local/PHP' '–with-config-file-path=/etc' '–with-MySQL=/usr/local/mysql' '–with-mysqli=/usr/local/mysql/bin/mysql_config' '–with-iconv-dir=/usr/local' '–with-fre

qtopia编译错误

在编译过程中会出现很多的错误,包括飞凌提供的ok6410 QT移植百科全书里面的,但是手册里面罗列的不全,下面我将我在编译过程实际遇到的编译错误及其解决办法写一下(其中的一些错误实际中没有遇到,是从网上搜集的,供朋友们参考):    错误一:        /usr/bin/ld: cannot find -lXmu        collect2: ld returned 1 exit status  错误二:         Creating pngscale...make[1]: Ente

Django2.2中Xadmin错误集

Xadmin 下载地址: https://github.com/sshwsfc/django-xadmin 遇见的错误 错误一:关联关系ForeignKey引发的错误,打开xadmin文件中的模型文件models.py,凡是出现关联关系字段的地方全部加上on_delete=models.CASCADE , 如下图所示: 错误二:模块包名称合并修改引发的错误  提示:ModuleNotFoundError: No module named 'django.core.urlresolvers' ,这

Spring常见的十大错误,78%的老程序员都踩过这些坑!

首先我们来看一下,Spring常见错误有那些 太过关注底 内部结构 "泄露" 缺乏关注点分离 缺乏异常处理或处理不当 多线程处理不当 不使用基于注解的验证 (依旧)使用基于xml的配置 忽略 profile 无法接受依赖项注入 缺乏测试,或测试不当 接下来就一一介绍这些常见的错误1. 错误一:太过关注底层我们正在解决这个常见错误,是因为 "非我所创" 综合症在软件开发领域很是常见.症状包括经常重写一些常见的代码,很多开发人员都有这种症状.虽然理解特定库的内部结构及其

Spring常犯的十大错误,你踩过吗?

1.错误一:太过关注底层 我们正在解决这个常见错误,是因为 "非我所创" 综合症在软件开发领域很是常见.症状包括经常重写一些常见的代码,很多开发人员都有这种症状. 虽然理解特定库的内部结构及其实现,在很大程度上是好的并且很有必要的(也可以是一个很好的学习过程),但作为软件工程师,不断地处理相同的底层实现细节对个人的开发生涯是有害的. 像 Spring 这种抽象框架的存在是有原因的,它将你从重复地手工劳作中解放出来,并允许你专注于更高层次的细节 -- 领域对象和业务逻辑. 因此,接受抽象

linux下编译安装php各种报错大集合

PHP开源脚本语言 PHP(外文名: Hypertext Preprocessor,中文名:"超文本预处理器")是一种通用开源脚本语言.语法吸收了C语言.Java和Perl的特点,入门门槛较低,易于学习,使用广泛,主要适用于Web开发领域.PHP的文件后缀名为php. 本文为大家整理汇总了一些linux下编译安装php各种报错大集合 ,感兴趣的同学参考下. 报错1:make 后报错如下: Generating phar.php /home/oldboy/tools/php-5.3.27

第一篇、python

以下都是基于python3环境但(也支持2.7只要注意语法) 一.添加解释器 文件书写的时候需要标识由哪个解释器来执行.还需要添加中文解释器 1 #!/usr/bin/env python 2 #-*- coding:utf-8 -*- 二.注释 #当行注释 """ 这是多行注释 """ ''' 这个也是多行注释 ''' 三.字节码 自带的(内置模块) 下载的 自己写的 写一个文件 m.py #/usr/bin/env python #-*-co

android源码的编译问题总结

由于目前的项目需要修改android的内核源码,所以我需要从android源码的编译开始学习. 下面看一下我的编译环境. 我使用的Ubuntu系统的版本是14.04,64位. gcc版本:4.8.8 编译过程我是看着google开发者官网,以及结合别人的博客进行编译的.编译的过程会遇到很多问题,在这里,我就把我遇到的问题总结一些,以便以后用到的时候容易查看,也方便别人编译android的时候遇到相同的问题,便于查看. 问题一:java版本问题 这个问题描述的是我当前使用的java版本是"1.7&