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') 

    相关文章:

    • 2022-12-23
    • 2021-11-20
    • 2021-10-02
    • 2022-01-07
    • 2021-12-13
    • 2021-06-04
    • 2022-01-15
    • 2022-12-23
    猜你喜欢
    • 2022-02-04
    • 2021-10-31
    • 2022-12-23
    • 2022-12-23
    相关资源
    相似解决方案