我不能在Freemarker模板中读取scala/java对象的值。
我尝试了以下代码:
case class ScheduleEmail(workOrderNo:String,
name:String,
woType:String,
numberOfAssets:String,
artisan:String,
dueDate:Date,priority:String)
object ScheduleMailSending extends App{
val scheduleEmail1= List(ScheduleEmail("1", "Oil Change1", "WO", "3", "XYZ", Date.valueOf("2015-01-01"), "High"))
val configaration = new Configuration
configaration.setClassForTemplateLoading(this.getClass, "/")
configaration.setObjectWrapper(new DefaultObjectWrapper())
val data: util.HashMap[String, Object] = new util.HashMap[String, Object]
val templet = configaration.getTemplate("schedule.ftl")
data.put("mails",scheduleEmail1.asJava)
val writer =new StringWriter()
templet.process(data,writer)
println("writer"+writer)
}
我的模板是-
<#list mails as std>
WorkOrderNo:${std.workOrderNo}
woType:${std.woType}
</#l
我正在与这个错误进行斗争-
SEVERE: Error executing FreeMarker template
FreeMarker template error:
For "${...}" content: Expected a string or something automatically convertible to string (number, date or boolean), but this evaluated to a sequence+method (wrapper: f.e.b.SimpleMethodModel):
==> std.workOrderNo [in template "schedule.ftl" at line 2, column 15]
The failing instruction (FTL stack trace):
----------
==> ${std.workOrderNo} [in template "schedule.ftl" at line 2, column 13]
----------
Java stack trace (for programmers):
有人能帮助我解决这个问题吗?