xml使用foreach
public class OrderScenicBindParam implements Serializable { private Long orgId; private List<Long> parkList; public Long getOrgId() { return orgId; } public void setOrgId(Long orgId) { this.orgId = orgId; } public List<Long> getParkList() { return parkList; } public void setParkList(List<Long> parkList) { this.parkList = parkList; } }
List<Long>类型的入参 parkList
<select id="selectScenicCodeByParkList" parameterType="cn.galasys.clota.ota.entity.OrderScenicBindParam" resultType="Long"> select distinct code from order_scenic_bind_rule where is_deleted = 'false' and status = 'true' and org_id = #{orgId} and ( <foreach collection="parkList" item="parkId" index="index" separator="or"> scenic_id like concat('%',#{parkId},'%') </foreach> ) </select>
String类型的入参 visitorId(1,2,3,4),使用 split(,)拆分成数组
<select id="selectBlockGuestList" parameterType="cn.galasys.clota.ota.vo.hotel.HotelParam" resultType="cn.galasys.clota.ota.vo.hotel.BlockGuestDto"> SELECT ov.visitor_type as visitorType,ov.visitor_name as visitorName,ov.document_info as documentInfo,ov.phone_number as phoneNumber, ov.document_type as documentType,ov.document_code as documentCode,ov.gender,ov.age_qualifying_code as ageQualifyingCode,ov.guest_type as guestType FROM order_visitor ov WHERE ov.order_id = #{orderId} AND ov.visitor_type = #{visitorType} AND ov.is_deleted = 'false' <if test="visitorId != null and visitorId != ''"> and ov.id in <foreach item="visId" collection="visitorId.split(',')" open="(" separator="," close=")" index="index" > #{visId} </foreach> </if> </select>
参考:https://blog.csdn.net/qqqwwweeerasd/article/details/122990644