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>
  • 相关阅读:
    postman设置页面详解
    postman安装使用
    测试入门1:黑盒测试用例设计方法
    oo第十六次作业
    oo第三单元总结
    OO第二单元总结
    select语句
    MySQL数据库基础操作
    创建和查看数据库
    认识MySQL数据库
  • 原文地址:https://www.cnblogs.com/chenligeng/p/9946123.html
Copyright © 2011-2022 走看看