Mybatis中sql数组为空判断

一、Mybatis xml中的sql通过if语句判定是否为空
xml 复制代码
<if test="arrays != null">
</if>

上述示例只能判断arrays数组不为null,那如果是个空数组呢

二、Mybatis xml中的sql通过if语句判定数组非空数组

xml 复制代码
<if test="arrays != null and arrays.length > 0">
</if>

如果是按照上述写法,将会报如下已异常:

sh 复制代码
nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'arrays != null and arrays.length > 0'. Cause: org.apache.ibatis.ognl.NoSuchPropertyException: java.util.ArrayList.length

正确写法如下:

xml 复制代码
<if test="arrays != null and arrays.size() > 0">
</if>

开源SDK:https://github.com/mingyang66/spring-parent

相关推荐
DBA_G1 小时前
南大通用GBase 8s数据库新存储引擎核心能力二
数据库·微服务·架构
衣乌安、2 小时前
数据库事务原理与回滚机制
数据库
CodexDave3 小时前
PostgreSQL 明明有索引却选了 Nested Loop:从行数误判修正执行计划
数据库·postgresql·执行计划·扩展统计·nestedloop
czhaii5 小时前
STC ai助手单片机工程项目创建实例
数据库·mongodb
山峰哥5 小时前
数据库性能救星:Explain执行计划深度拆解
服务器·开发语言·数据库·sql·启发式算法
oradh6 小时前
Oracle 11g rac IP地址修改(public ip、vip、scan ip、priviate ip)
数据库·tcp/ip·oracle·rac ip地址修改
YOU OU6 小时前
Redis哨兵 & 集群
数据库·redis·sentinel
小罗水6 小时前
第8章 文档解析与文本切片
数据库·spring·spring cloud·微服务
瞬间&永恒~7 小时前
【MySQL】 主从复制多拓扑搭建实验
运维·数据库·mysql·云原生