Mybatis - 如何检查 int 数组是否为空/空

问题描述

我有以下示例 mybatis 方法。我正在使用 Postgresql 数据库。 我必须在以下查询中使用 eventTypeIds。因此,如果 eventTypeIds 不为 null 或不为空,则检查条件 (e.event_type_key= any(#{eventTypeIds})) 否则返回 true。

@Select("SELECT *  FROM TEST e WHERE  e.city_key = ANY(#{cityIds}) and 
(CASE WHEN (#{objectName} <> '' IS NOT TRUE) THEN true ELSE (e.object_name = #{objectName}) END)")
@Results(value = { 
            @Result(property = "id",column = "id"),@Result(property = "name",column = "name")         
            })  
public List<Test> get(@Param("cityIds") int[] cityIds,@Param("objectName") String objectName,@Param("eventTypeIds") int[] eventTypeIds);

eventTypeIds 是一个原始 int 数组。

我如何检查 eventTypeIds 是 null 还是空,以便我可以应用我的逻辑,如下所示?

(CASE WHEN (#{eventTypeIds} is null or is empty) THEN true ELSE (e.event_type_key = ANY(#{eventTypeIds})) END)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)