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

版本一

<select id="SelectByNameAndParentId resultMap="Base_result" parameterType="map"">

select

<include refid="Base_column_List"/>

from mmall_product

<if test="productId !=null">

where id = #{productId}

</if>

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

</if>

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

版本二

<select id="SelectByNameAndParentId resultMap="Base_result" parameterType="map"">

select

<include refid="Base_column_List"/>

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 id="SelectByNameAndParentId" resultMap="BaseResult" parameterType="map">
select
<include refid="Base_column_List"/>
from mmall_product
<where>
<if test="productName != null">
and name like #{productName}
</if>
<if test="productId !=null">
and id = #{id}
</id>
</where>
</map>

最新文章

  1. Nginx+lua环境搭建
  2. 通过j-interop访问WMI实例代码
  3. CSS(一)
  4. linux服务之ssh
  5. 7 款开源 Java 反编译工具
  6. 折腾了半天,终于搞定了apache的rewrite功能
  7. 5个Xcode开发调试技巧
  8. jsp 页面通过jq处理默认 选中的项 数据是通过遍历显示
  9. 教你修改Linux下高并发socket最大连接数所受的各种限制
  10. js复制对象 和 节点类型和NodeList
  11. 浅谈HtmlParser
  12. Struts2拦截器总结
  13. 《安卓网络编程》之第五篇 WebView的使用
  14. Ubuntu16.0.4的磁盘管理
  15. URL控制器
  16. CABaRet: Leveraging Recommendation Systems for Mobile Edge Caching
  17. KASAN实现原理【转】
  18. javase的网络编程(InetAddress,UDP,TCP,URL,Socket,DatagramSocket)
  19. 2014-2015 ACM-ICPC, Asia Xian Regional Contest GThe Problem to Slow Down You
  20. Ubuntu18.04 更换源

热门文章

  1. http(数据格式)、postman(数组、id、断言) 小知识必看啊
  2. WPF xml配置文件里面的大于小于号转义
  3. php 跨域问题 解决办法
  4. java反射应用
  5. 爬虫之requests
  6. 升级linux python
  7. SQLALchemy中关于复杂关系表模型的映射处理
  8. sql语句的优先级
  9. 打包发布到Tomcat
  10. cenos 修改静态ip