<selectid="findByName"parameterType="String"resultType="YourEntityType"> SELECT * FROM your_table WHERE 1=1 <iftest="name != null and name != ''"> AND name LIKE CONCAT('%', #{name}, '%') </if> </select>
oracle
oracle没有mysql的concat()函数
<selectid="findByName"parameterType="String"resultType="YourEntityType"> SELECT * FROM your_table <where> <iftest="name != null and name != ''"> AND name LIKE '%' || #{name} || '%' </if> </where> </select>
如果上面的报错,那么可以使用bind标签
<selectid="findByName"parameterType="String"resultType="YourEntityType"> SELECT * FROM your_table WHERE <iftest="name != null and name != ''"> <bindname="nameBind"value="'%' + name + '%'" /> name LIKE #{nameBind} </if> </select>
SELECT material.PK_MATERIAL materialPk, pp.FBILLSTATUS billStatus, FROM PO_PRAYBILL_B ppb LEFT JOIN BD_MATERIAL_V material ON material.PK_MATERIAL = ppb.pk_material LEFT JOIN PO_PRAYBILL pp ON pp.PK_PRAYBILL = ppb.PK_PRAYBILL WHERE pp.dr = 0 AND ppb.dr = 0 AND material.dr = 0 AND pp.fpraysource = 9 AND pp.PK_ORG = #{pkOrg} <choose> <whentest="sourceCodeSet !=null and sourceCodeSet.size()>0"> AND ppb.VSOURCECODE in <foreachitem="item"index="index"collection="sourceCodeSet"open="("separator=","close=")"> #{item} </foreach> </when> <otherwise> AND 0 = 1 </otherwise> </choose>