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

相关推荐
悄悄敲敲敲4 小时前
MySQL表的约束
数据库·mysql
鼠爷ねずみ4 小时前
SpringCloud前后端整体开发流程-以及技术总结文章实时更新中
java·数据库·后端·spring·spring cloud
九皇叔叔4 小时前
MySQL 数据库 Read View 详解
数据库·mysql·mvcc·read view
Elastic 中国社区官方博客5 小时前
Elasticsearch:圣诞晚餐 BBQ - 图像识别
大数据·数据库·elasticsearch·搜索引擎·ai·全文检索
cui_win5 小时前
Prometheus实战教程 - Redis 监控
数据库·redis·prometheus
JIngJaneIL6 小时前
基于java + vue个人博客系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
TG:@yunlaoda360 云老大6 小时前
华为云国际站代理商备份策略设置过程中遇到问题如何解决?
服务器·数据库·华为云
SelectDB6 小时前
Doris Catalog 已上线!性能提升 200x,全面优于 JDBC Catalog,跨集群查询迈入高性能分析时代
数据库·数据分析·apache
TAEHENGV6 小时前
进度跟踪模块 Cordova 与 OpenHarmony 混合开发实战
android·javascript·数据库
神秘面具男037 小时前
MySQL 从基础到实践
数据库·mysql