mybatis
对 in 的优化
原文 : https://blog.csdn.net/weixin_39300480/article/details/103187485
原文这里的参数为list,这里我用的,分割的字符串
思路就是将in中的数据处理成一个表,进行表的关联查询 替换掉in
select
fm.id,
fm.configuration_id,
fm.name_code,
fm.manufactor_code,
fm.type,
fm.is_sign_board,
fm.is_diagnostic_screen,
fm.add_time,
fm.update_time,
fm.is_template,
fm.hospital_type,
fm.hospital_code from do_facility_examination as fm
<if test="null != hospitalCode and '' != hospitalCode">
inner join (
<foreach item="item" index="index" collection="hospitalCode.split(',')" separator="UNION ALL" >
select #{item} as hospital_code
</foreach>
) as hospital_model
on fm.hospital_code=hospital_model.hospital_code
</if>
<where>
<if test="hospitalType != null ">and fm.hospital_type = #{hospitalType}</if>
</where>
主要参数为 separator=“UNION ALL” 这里使用 UNION ALL 进行拼接会将查询出来的数据树形返回。