select id, sjbh, barxm, barxmpym, barxbid, bafsid, jbsj, sjlxid, operatercode, operatetime, gzqk, cljg, bz, isdel, orgid, bldwid, blmj, blmjzh, lrdwid, lrrzh, lrrq, zhbs, sjlyflg,jqbh,bjnr from sjgl_sj_sjjbxx where zhbs is null AND isdel='0' <if test="sjbh != null and sjbh != ''"> AND sjbh like '${sjbh}%' </if> <if test="jqbh != null and jqbh != ''"> AND jqbh like '${jqbh}%' </if> <if test="bjnr != null and bjnr != ''"> <foreach collection="bjnr.split(',')" item="item" index="index" separator=" "> AND bjnr like '%${item}%' </foreach> </if>
separator 是前面的逗号切割之后中间加的值,我用空,其实可以用 OR bjnr like 然后把 AND bjnr lik放外面
<if test="bjnr != null and bjnr != ''"> AND bjnr like <foreach collection="bjnr.split(',')" item="item" index="index" separator=" OR bjnr like "> '%${item}%' </foreach> </if>
sql语句就不一样了