freemarker 不支持 boolean 类型

If in a template <td>${attribute.value}</td> is used, and value is boolean, the following exception is thrown:
freemarker.core.NonStringException: Error on line 19, column 3 in description.ftl
Expecting a string, date or number here, Expression a.value is instead a freemarker.ext.beans.BooleanModel
- quote: "..Unlike numbers, booleans has no commonly accepted format, not even a
common format within the same page. Like when you show on a HTML page.."
"...The common way of formatting a boolean is like ${washable?string("yes", "no")},
${caching?string("Enabled", "Disabled")}, ${heating?string("on", "off")}, etc..."
- By the other hand, the Features used in the unit test for FeatureTemplate contained no boolean properties. Adding a boolean property to the test data still didn't make the error to show up, as the template used uses <td>${attribute.value.toString()}</td>. Changing the template to use <td>${attribute.value}</td> exposes the error.

相关推荐