码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-09-21 10:49:03      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:文件   result   app   info   一个   java   map对象   没有   ring   

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

  <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可以让我们的代码变简洁,当然也有缺陷,就是会写很多弱类型的属性名。

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

标签:文件   result   app   info   一个   java   map对象   没有   ring   

原文地址:https://www.cnblogs.com/lori/p/9684893.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!