首页 > 数据库技术 > 详细

mybatis sql in 查询(mybatis sql语句传入参数是list)mybatis中使用in查询时in怎么接收值

时间:2016-12-16 22:15:53      阅读:526      评论:0      收藏:0      [点我收藏+]

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

mybatis sql in 查询(mybatis sql语句传入参数是list)mybatis中使用in查询时in怎么接收值

原文:http://www.cnblogs.com/panxuejun/p/6188409.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!