在做后台的商品搜索功能开发时遇到了一些问题记录下来

版本一

<select >

select 

<include ref/>

from mmall_product

<if test="productId !=null">

where id = #{productId}

</if>

<if test="productName !=null">
and name like {productName}

</if>

这个是有问题的如果第一个if没有传值过来,那么第二个if就不是正确的sql语句

版本二

<select >

select 

<include ref/>

from mmall_product

where 1 = 1

<if test="productId !=null">

and id = #{productId}

</if>

<if test="productName !=null">
and name like {productName}

</if>

</select>

这个没问题,但是为了看起来顺眼我么使用了<where>标签

最终版本
<select >
and id = #{id}
</id>
</where>
</map>

相关文章:

  • 2022-01-07
  • 2021-10-20
  • 2021-10-06
  • 2022-12-23
  • 2021-10-01
  • 2022-12-23
  • 2021-07-14
猜你喜欢
  • 2021-06-21
  • 2022-01-08
  • 2021-11-10
  • 2021-11-14
  • 2021-07-02
  • 2021-04-28
  • 2022-12-23
相关资源
相似解决方案