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

相关推荐
月光水岸New2 小时前
Ubuntu 中建的mysql数据库使用Navicat for MySQL连接不上
数据库·mysql·ubuntu
狄加山6752 小时前
数据库基础1
数据库
我爱松子鱼2 小时前
mysql之规则优化器RBO
数据库·mysql
chengooooooo2 小时前
苍穹外卖day8 地址上传 用户下单 订单支付
java·服务器·数据库
Rverdoser3 小时前
【SQL】多表查询案例
数据库·sql
Galeoto3 小时前
how to export a table in sqlite, and import into another
数据库·sqlite
人间打气筒(Ada)4 小时前
MySQL主从架构
服务器·数据库·mysql
leegong231114 小时前
学习PostgreSQL专家认证
数据库·学习·postgresql
喝醉酒的小白4 小时前
PostgreSQL:更新字段慢
数据库·postgresql
敲敲敲-敲代码4 小时前
【SQL实验】触发器
数据库·笔记·sql