一.错误显示
Caused by:
freemarker.core.NonNumericalException: Can't convert this string to number: ""|The blamed expression:|==> (warehouseClassId)?number [in template "/warehouse/info/list.ftl" at line 44, column 148]||The failing instruction:|==> #if warehouseClassId?? && r.id == (wa... [in template "/warehouse/info/list.ftl" at line 44, column 114]
at freemarker.core.NonNumericalException.newMalformedNumberException(NonNumericalException.java:98)
at freemarker.core.StringBuiltins$numberBI.calculateResult(StringBuiltins.java:223)
at freemarker.core.StringBuiltins$StringBuiltIn._eval(StringBuiltins.java:87)
at freemarker.core.Expression.eval(Expression.java:111)
at freemarker.core.EvalUtil.compare(EvalUtil.java:147)
at freemarker.core.ComparisonExpression.evalToBoolean(ComparisonExpression.java:103)
at freemarker.core.AndExpression.evalToBoolean(AndExpression.java:68)
at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:84)
at freemarker.core.Environment.visit(Environment.java:265)
at freemarker.core.MixedContent.accept(MixedContent.java:93)
at freemarker.core.Environment.visitByHiddingParent(Environment.java:286)
at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:193)
at freemarker.core.Environment.visitIteratorBlock(Environment.java:509)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:103)
at freemarker.core.Environment.visitByHiddingParent(Environment.java:286)
at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:86)
at freemarker.core.Environment.visit(Environment.java:265)
at freemarker.core.MixedContent.accept(MixedContent.java:93)
at freemarker.core.Environment.visit(Environment.java:265)
at freemarker.core.Environment.process(Environment.java:243)
at freemarker.template.Template.process(Template.java:277)
at org.springframework.web.servlet.view.freemarker.FreeMarkerView.processTemplate(FreeMarkerView.java:367)
at org.springframework.web.servlet.view.freemarker.FreeMarkerView.doRender(FreeMarkerView.java:284)
at org.spri
二:错误代码
<select name="warehouseClassId">
<option value="">选择仓库类别</option>
<#if (warehouseClassDTOList?exists && warehouseClassDTOList?size>0) >
<#list warehouseClassDTOList as r>
<option value="${r.id!}" <#if warehouseClassId??&&r.id== (warehouseClassId?number)>selected</#if>>${r.name!}</option>
</#list>
</#if>
</select>
三、解决方法
warehouseClassId从后端传过来是字符串,r.id是Long型,故报错,所以上网查了一下怎样将字符串转成数字,没错,就像上面的warehouseClassId?number一样,但还是没卵用还是报错,不知道为啥。。。
所以我决定投机取巧 将r.id变成 (r.id)?string,即将数字转成字符串,然而成功了。。。。。。
我还能说什么。。。。