zoukankan      html  css  js  c++  java
  • Mybatis使用IN语句查询 关于mybatis in操作使用foreach的问题解决

    直接简单粗暴

    一 、接口传递对象封装集合属性

    下面标记这种形式
    collection指的是对象属性myList
    例子

    User user = new User();
    user.setName("必须正解!");
    List<String> list = new ArrayList<>();
    list.add("1");   
    list.add("2");
    user.setMyList(list );
    接口直接传递User对象进去,属性直接接收就行,就是这个对象你要循环的属性(有其他的where 属性 也可以写进去,不影响)

    select * from User where name = #{name} and  id in 
    
    <foreach item="item" index="index" collection="myList" open="("  separator=","  close=")"   >
                    #{item}
          </foreach>

    二 、接口直接传递集合和数组

    不用想了 接口传递的肯定是List集合

    <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
    	  #{id}
    	</foreach>

    这肯定就是数组呗

    <foreach collection="array" item="id" index="index" open="(" close=")" separator=",">
    	  #{id}
    	</foreach>

    问题解决!!!

  • 相关阅读:
    【javaSE】Exception in thread "main" java.lang.ArrayStoreException: java.lang.Integer
    property
    多继承与super
    GIL全局解释器锁
    深浅拷贝
    生成器
    迭代器
    设置ll命令
    修改Centos中的ll命令(以 K 为单位显示文件大小)
    打包解压缩命令
  • 原文地址:https://www.cnblogs.com/liclBlog/p/15349479.html
Copyright © 2011-2022 走看看