MyBatis 引号分割字符串

在这里插入图片描述
在这里插入图片描述
runProperty 参数会有多个,比如“卡班车,网点车”

传到xml,

<if test="runProperty != null and runProperty != ''">
		AND RUN_PROPERTY IN 
		<foreach collection="runProperty" item="runProperty" index="index" open="(" separator="," close=")">
			#{runProperty}
		</foreach>
</if>

这样打印的sql如下图
在这里插入图片描述
这样肯定是不对的。


正确写法:
<if test="runProperty != null and runProperty != ''">
			AND RUN_PROPERTY IN 
			<foreach collection="runProperty.split(',')" item="runProperty" index="index" open="(" separator="," close=")">
				#{runProperty}
			</foreach>
</if>

已split(’,’)分割,得到的sql就是

RUN_PROPERTY in('卡班车','网点车') 

有什么更好的解决方案,欢迎大佬指教!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章