感谢:http://hi.baidu.com/imaogo/blog/item/46daa794006cf81dd31b70f3.html
问题:
freemarker在模板中的数据比如1024,超过1000,就会变成1,024
怎么样让它原样输出
回答:
可在web.xml里面配置
<servlet>
<servlet-name>freemarker</servlet-name>
<servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class>
<!-- FreemarkerServlet settings: -->
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/WEB-INF/template</param-value>
</init-param>
<init-param>
<param-name>NoCache</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>ContentType</param-name>
<param-value>text/html</param-value>
</init-param>
<!-- FreeMarker settings: -->
<init-param>
<param-name>template_update_delay</param-name>
<param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. -->
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>locale</param-name>
<param-value>en_US</param-value>
</init-param>
<init-param>
<param-name>number_format</param-name>
<param-value>0.##########</param-value>
</init-param>
<init-param>
<param-name>date_format</param-name>
<param-value>yyyy-MM-dd</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping>
另外补充一点,如果只是用ftl展示数据的话,以上配置是可以的。但是如果用ftl作模版生成Html时,可能还会出现类似问题,这好像是freemarker的一个bug,所以还需要在代码里面显式的设置
Configuration cfg = new Configuration()
....
cfg.setNumberFormat("0.##########");