You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Thymeleaf条件运算符报错:无法解析表达式

解决Thymeleaf条件表达式解析错误问题

问题原因

你在代码里使用了HTML实体&amp;le;(对应符号≤),但Thymeleaf的OGNL表达式不支持这种写法,必须使用标准的EL比较运算符<=。

修正后的代码

<p th:if="${modelMap.languages.size() <= 2}" th:text="Items are less">Items are less</p>

额外优化建议

  • 若modelMap.languages可能为null,需先做空判断避免空指针异常:
    <p th:if="${modelMap.languages != null and modelMap.languages.size() <= 2}" th:text="Items are less">Items are less</p>
    
  • 更推荐用Thymeleaf内置工具类#lists,它会自动处理null列表(返回0),写法更安全:
    <p th:if="${#lists.size(modelMap.languages) <= 2}" th:text="Items are less">Items are less</p>
    

内容的提问来源于stack exchange,提问作者Mukul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 01:27:06