mybatis sql in 查詢(mybatis sql語句傳入參數是list)mybatis中使用in查詢時in怎么接收值


1.in查詢條件是list時

<select id="getMultiMomentsCommentsCounts" resultType="int">
select moment_comment_count from tbl_moment_commentCount where mid in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")"> 
    #{item} 
</foreach> 
</select>

.1 如果參數的類型是List, 則在使用時,collection屬性要必須指定為 list

  1. <select id="findByIdsMap" resultMap="BaseResultMap">  
  2.  Select  
  3.  <include refid="Base_Column_List" />  
  4.  from jria where ID in  
  5.  <foreach item="item" index="index" collection="list" open="(" separator="," close=")">  
  6.   #{item}  
  7.  </foreach>  
  8. </select>  

2.in查詢條件是枚舉值時

默認下,使用select xxx where in(xx,xx)查詢,返回結果是按主鍵排序的,如果要按in()中值的排列順序,可以這樣做:
 
select * from talbe where id in(3,2,4,1) ORDER BY FIND_IN_SET( id, '3,2,4,1') 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM