ftl页面报错The only legal comparisons are between two numbers, two strings, or two dates
在freemarker的ftl页面中if标签常常会报freemarker.template.TemplateException: The only legal comparisons are between two numbers, two strings, or two dates.的错误。
例如
<#if 1=="${1?if_exists?html}"></#if>这句话就会报错,因为1是int类型,"${1?if_exists?html}"是字符串,不同类型比较失败。
解决方法:把int类型转成字符串即可。修改如下:
<#if "1"=="${1?if_exists?html}"></#if>
或
<#if "${1?if_exists?html}"=="${1?if_exists?html}"></#if>
本文地址:http://yayihouse.com/yayishuwu/chapter/1066