好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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

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

?

1

2

3

4

5

6

7

8

<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查询的实现方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

查看更多关于java~springboot~ibatis数组in查询的实现方法的详细内容...

  阅读:22次