溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Mybatis怎么根據List批量查詢List結果

發(fā)布時間:2022-03-11 11:38:30 來源:億速云 閱讀:708 作者:iii 欄目:開發(fā)技術

這篇文章主要介紹“Mybatis怎么根據List批量查詢List結果”的相關知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“Mybatis怎么根據List批量查詢List結果”文章能幫助大家解決問題。

根據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>

數(shù)組參數(shù)

//接口方法
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參數(shù)

//接口方法
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>

根據多條件List查詢

mapper文件

<select id="selectWhere" resultMap="BaseResultMap">
    select 
     <include refid="Base_Column_List" />
    from table
     <where>
      table.a = a  and table.b in 
    <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
      '${item}'
    </foreach>
    </where>
  </select>

DAO片段

List<T> selectWhere(@Param("list")List<String> list ,@Param("a") String a);

關于“Mybatis怎么根據List批量查詢List結果”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識,可以關注億速云行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI