zoukankan      html  css  js  c++  java
  • Mybatis根据List批量查询List结果

    一、mapper接口

    /**
     * 根据剧典id list查询剧典
     */
    public List<Drama> selectByIds(@Param("dramaIds")List<Long> dramaIds);

    二、mapper.xml文件

    <!-- 根据剧典id list查询剧典 -->
    <select id="selectByIds" resultMap="DramaImageResultMap">
        select * from drama where drama_id in 
        <foreach collection="dramaIds" item="dramaId" open="(" close=")" separator=",">
        #{dramaId}
       </foreach>
    </select>

    数组参数

    //接口方法
    ArrayList<User> selectByIds(Integer [] ids);
    //xml映射文件
    <select id="selectByIds" resultMap="BaseResultMap">
        select
        *
        from user where id in
        <foreach item="item" index="index" collection="array" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    List参数

    //接口方法
    ArrayList<User> selectByIds(List<Integer> ids);
    //xml映射文件
    <select id="selectByIds" resultMap="BaseResultMap">
        Select
        <include refid="Base_Column_List" />
        from jria where ID in
        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
              #{item}
          </foreach>
      </select> 
  • 相关阅读:
    BZOJ 1014 火星人prefix
    BZOJ 1013 球形空间产生器
    BZOJ 1012 最大数
    BZOJ 1011 遥远的行星
    BZOJ 1010 玩具装箱
    BZOJ 1009 GT考试
    BZOJ 1008 越狱
    BZOJ 1007 水平可见直线
    BZOJ 1006 神奇的国度
    Luogu 1450 [HAOI2008]硬币购物
  • 原文地址:https://www.cnblogs.com/lvchengda/p/12599740.html
Copyright © 2011-2022 走看看