mybatis的xml中用foreach分隔逗号的写法
holidayTypeStr传进来的是这种形式:‘1,2,3,4,5’,很明显,这样在in中遍历会报错,所以需要逗号分隔结果变成这种形式’1’,‘2’,‘3’,‘4’;
关键点:collection=“holidayTypeStr.split(‘,’)”
<select id="selectHolidayInfo" resultMap="BaseResultMap" parameterType="com.accurad.amol.hospital.entity.SysHolidayInfo" >
select
<include refid="Base_Column_List" />
from sys_holiday_info
where holiday_type IN
<foreach collection="holidayTypeStr.split(',')" item="holidayType" open="(" close=")" separator=",">
#{holidayType}
</foreach>
AND holiday_date <![CDATA[>=]]> #{beginTime}
AND holiday_date <![CDATA[<=]]> #{endTime}
</select>