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

相关推荐
龙仔7253 小时前
人大金仓OS_Core数据库自动备份实施笔记(银河麒麟Linux)
linux·数据库·笔记·备份·人大金仓
sunxr.2273 小时前
Mysql-----最后一次作业
数据库·mysql
普通网友3 小时前
Python FastAPI 异步数据库管理
数据库·fastapi
晓子文集4 小时前
Tushare接口文档:期货合约信息表(fut_basic)
大数据·数据库·金融·金融数据·量化投资
三言老师4 小时前
CentOS7.9:Redis‑Cluster集群部署结构化实战教程
linux·运维·服务器·数据库
旺仔学长 哈哈5 小时前
Spring Boot 智能停车场管理系统---附源码+数据库文档
数据库·spring boot·后端·智能停车场
ClickHouseDB5 小时前
ClickHouse托管Postgres:OLTP+OLAP,新能力解锁最佳数据平台
java·前端·数据库
数智化管理手记6 小时前
主数据重复、错漏频发?一站式主数据管理平台如何落地?
大数据·运维·数据库·人工智能·数据挖掘
吴声子夜歌6 小时前
MongoDB 4.2——选择片键
数据库·mongodb
吴声子夜歌6 小时前
MongoDB 4.2——安全介绍
数据库·安全·mongodb