freemarker.template.TemplateException: Expected string. column.nullable evaluated instead to freemar

错误信息:

五月 11, 2017 5:03:32 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error
严重: Template processing error: "Expected string. column.nullable evaluated instead to freemarker.template.TemplateBooleanModel$1 on line 61, column 86 in baseTemplate/java_src/${basepackage_dir}/interfaceDoc/${className}Doc.html."

Expected string. column.nullable evaluated instead to freemarker.template.TemplateBooleanModel$1 on line 61, column 86 in baseTemplate/java_src/${basepackage_dir}/interfaceDoc/${className}Doc.html.
The problematic instruction:
----------
==> ${column.nullable?right_pad(5," ")} [on line 61, column 84 in baseTemplate/java_src/${basepackage_dir}/interfaceDoc/${className}Doc.html]
----------

Java backtrace for programmers:
----------
freemarker.template.TemplateException: Expected string. column.nullable evaluated instead to freemarker.template.TemplateBooleanModel$1 on line 61, column 86 in baseTemplate/java_src/${basepackage_dir}/interfaceDoc/${className}Doc.html.
	at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:136)
	at freemarker.core.BuiltIn$right_padBI._getAsTemplateModel(BuiltIn.java:1332)
	at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
	at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:86)
	at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
	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.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
	at freemarker.core.Environment.visit(Environment.java:428)
	at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
	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 cn.org.rapid_framework.generator.Generator.saveNewOutputFileContent(Generator.java:233)
	at cn.org.rapid_framework.generator.Generator.generateNewFileOrInsertIntoFile(Generator.java:167)
	at cn.org.rapid_framework.generator.Generator.generateByModelProvider(Generator.java:126)
	at cn.org.rapid_framework.generator.Generator.generateByModelProvider(Generator.java:83)
	at cn.org.rapid_framework.generator.GeneratorFacade.generateByTable(GeneratorFacade.java:117)
	at cn.org.rapid_framework.generator.GeneratorMain.main(GeneratorMain.java:76)

Exception in thread "main" java.lang.RuntimeException: generate 'Database Table:equipment to ClassName:Equipment' oucur error,template is:baseTemplate/java_src/${basepackage_dir}/interfaceDoc/${className}Doc.html
	at cn.org.rapid_framework.generator.Generator.generateByModelProvider(Generator.java:128)
	at cn.org.rapid_framework.generator.Generator.generateByModelProvider(Generator.java:83)
	at cn.org.rapid_framework.generator.GeneratorFacade.generateByTable(GeneratorFacade.java:117)
	at cn.org.rapid_framework.generator.GeneratorMain.main(GeneratorMain.java:76)
Caused by: freemarker.template.TemplateException: Expected string. column.nullable evaluated instead to freemarker.template.TemplateBooleanModel$1 on line 61, column 86 in baseTemplate/java_src/${basepackage_dir}/interfaceDoc/${className}Doc.html.
	at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:136)
	at freemarker.core.BuiltIn$right_padBI._getAsTemplateModel(BuiltIn.java:1332)
	at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
	at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:86)
	at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
	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.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
	at freemarker.core.Environment.visit(Environment.java:428)
	at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
	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 cn.org.rapid_framework.generator.Generator.saveNewOutputFileContent(Generator.java:233)
	at cn.org.rapid_framework.generator.Generator.generateNewFileOrInsertIntoFile(Generator.java:167)
	at cn.org.rapid_framework.generator.Generator.generateByModelProvider(Generator.java:126)
	... 3 more

有文章 提到使用

  ${ isExit ?string("true","false")}


但我亲测根本不能用,

后来发现是我的freeMarker 的版本问题;


由于 column.nullable 是 Boolean 类型, freemarker 2.3.19 默认不支持 Boolean 类型

请升级到最新版本:2.3.26


<input name="isExit" type="hidden" value="${isExit?string('true','false')}" />  


freemarker用于取布尔类型的值:

实际例子:


重点:${basic.isDelete?string ("true","false")}"

说明:用于取布尔类型的值,string 用于将布尔值转换为字符串输出,true转为“true”,false转换为“false”,basic源于<#list business.result as basic></#list>,idDeletejavaBean里面的一个属性。


freemarker 低版本不支持布尔类型,而且 ${column.isNullable} ${column.nullable} 都会查找相同的方法;


你可能感兴趣的:(freemarker,boolean)