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

相关推荐
老华带你飞11 分钟前
海产品销售系统|海鲜商城购物|基于SprinBoot+vue的海鲜商城系统(源码+数据库+文档)
java·前端·数据库·vue.js·论文·毕设·海鲜商城购物系统
合作小小程序员小小店30 分钟前
桌面开发,在线%超市销售管理%系统,基于vs2022,c#,winform,sql server数据
开发语言·数据库·microsoft·c#
SelectDB35 分钟前
字节跳动:Apache Doris + AI 一站式融合数据引擎的探索与实践
数据库·apache
IvorySQL1 小时前
PostgreSQL 18 - 时间约束 (Temporal Constraints)
数据库·postgresql·开源
q***61411 小时前
从MySQL迁移到PostgreSQL的完整指南
数据库·mysql·postgresql
N***73852 小时前
SQL锁机制
java·数据库·sql
小羊在奋斗2 小时前
MySQL表的约束:从基础到核心(附场景+案例)
android·数据库·mysql
Wang's Blog2 小时前
MongoDB小课堂: 文档查询之匹配查询与比较操作符深度解析
数据库·mongodb
cookqq2 小时前
mongodb根据索引IXSCAN 查询记录流程
数据结构·数据库·sql·mongodb·nosql
p***32352 小时前
如何使用C#与SQL Server数据库进行交互
数据库·c#·交互