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
- <select id="findByIdsMap" 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>
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')