zoukankan      html  css  js  c++  java
  • 后台商品搜索功能开发SQL

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

    版本一

    <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>
  • 相关阅读:
    2019年6月英语四六级试题及答案和视频教程
    经典解压缩软件 WinRAR 5.90 sc 官方去广告版
    会动的边框
    萌萌达机器人
    背景图片跟随鼠标动
    烟花代码
    常用正则表达式
    计算器
    顶部下啦菜单
    ps用画笔工具设计水墨圆环
  • 原文地址:https://www.cnblogs.com/chenligeng/p/9946123.html
Copyright © 2011-2022 走看看