freemarker出现NonNumericalException异常

目录
  1. 问题
  2. 解决

问题

使用Freemarker作为模板引擎出现了NonNumericalException异常。错误如下:

1
2
ERROR freemarker.runtime - Error executing FreeMarker template  
freemarker.core.NonNumericalException: For "#{...}" content: Expected a number, but this has evaluated to a string (wrapper: f.t.SimpleScalar):

确认了模板数据没有问题,模板及数据都是字符串类型。

解决

不应该使用 #{…}, 应该要使用 ${…}

平常使用较多的表示式有些混淆,这个问题当时找了好久,遂记之。