java~springboot~ibatis数组in查询的实现

在ibatis的xml文件里,咱们去写sql语句,对应mapper类的方法,这些sql语句与控制台上没什么两样,但在有些功能上须要注意,如where in这种从数组里查询符合条件的集合里,须要在xml里进行特别的处理。sql

<update id="batchUpdate" parameterType="map">
        update customer_info set status=#{status},appoint_time=#{appointTime} where
        customer_id in
        <foreach collection="customerIdArr" item="customerId"
                 index="index" open="(" close=")" separator=",">
            #{customerId}
        </foreach>
    </update>

咱们能够看到,在xml里进行了foreach的遍历,而外部参数是一个集合或者数组的对象,咱们在xml对它进行遍历,仍是比较方便的。数组

技巧:在xml里,parameterType是输入参数类型,你能够使用map对象来代替;而resultType是返回类型,若是你没有定义DTO也能够使用map代替,虽然map能够让咱们的代码变简洁,固然也有缺陷,就是会写不少弱类型的属性名。app

相关文章
相关标签/搜索