Linux 拨号vps windows公众号手机端

mybatis判断集合为空的方法是什么

lewis 9年前 (2016-12-18) 阅读数 9 #程序编程
文章标签 mybatis

在MyBatis中,可以使用OGNL表达式语言中的isEmpty()函数来判断集合是否为空。

例如,在MyBatis的select语句中可以这样判断集合是否为空:

<select id="selectUsers" resultMap="userResultMap">
    SELECT * FROM users
    <where>
        <if test="userIds != null and !userIds.isEmpty()">
            AND user_id IN
            <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
                #{userId}
            </foreach>
        </if>
    </where>
</select>

在上面的例子中,userIds是一个List类型的参数,我们通过isEmpty()函数判断是否为空,如果不为空则执行相应的SQL语句。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门