您的位置:首页 > 其它

Mybatis实现in查询(注解形式和xml形式)

2018-01-12 15:40 471 查看
1. @Select注解中使用in

@Select({"<script> " +
" select * "+
" from business_threat bt \n" +
" join abnormal_event_type aet on bt.event_type_id = aet.id " +
" where 1=1 " +
" <if test = \" ids != null \"> " +
" and bt.id in " +
" <foreach item = 'item' index = 'index' collection = 'ids' open = '(' separator = ',' close = ')' > " +
" #{item} " +
" </foreach> " +
" </if> " +
"</script>"})
List<BusinessThreatVO> getByBusinessThreadId(@Param("ids") List<Long> ids);


2. xml中使用in

<select id="findByModelInMarket" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from device
WHERE replace(lower(model_in_market), ' ', '') = replace(lower(#{modelInMarket}), ' ', '')
AND status IN <foreach collection="deviceStatus" item="status" open="(" close=")" separator=",">#{status}</foreach>
</select>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: