第一种:

1
2
3
4
5
<if test="proName !=null and proName !='null'">

<bind name="gou" value="'%'+proName+'%'"/>
and product_name like #{gou}
</if>

第二种:

1
2
3
<if test="proName !=null and proName !='null'">
and product_name like '%'||#{proName}||'%'
</if>

第三种:

1
2
3
<if test="proName !=null and proName !='null'">
and product_name like '%'+#{proName}+'%'
</if>

第四种:

1
2
3
<if test="proName !=null and proName !='null'">
and product_name like concat('%',#{name},'%')
</if>

如果写成 “%#{xxx}%” ,#{xxx}就成了字符串的一部分,就变成 %xxx的内容% 这是个字符串

要写成: “%”#{xxx}”%”,#{xxx} 不能被字符串括起来,再前后加上%