gjq1126-web
<select id = "" resultMap = "">
select * from table
<where>
  <if test="type == \'x1\' ">
      and  条件1;
   </if>
  <if test="type == \'x2\' ">
    and 条件2;
  </if>
</where>
</select>


或者

<select id = "" resultMap = "">

  select * from table

   <choose>

        <when test=" type == \'x1\' \'">

              where   条件1;

       </when >

       <when test=" type == \'x2\' \'">

          where  条件2;

    </when > 

       <otherwise>

         条件3;   // 可以为空

       </otherwise>

   </choose>

   <if test="type == \'x2\' ">   //如果除了以上条件外还有判断的条件,放在chose标签外,不用再写where 

    and  条件2;

  </if>

</select>



例子:
<
select id="queryList" resultType="com....."> select * from student WHERE 1=1 <if test="name != null and name != \'\'"> AND name LIKE concat(\'%\',#{name},\'%\') </if> <if test="merchantId != null and merchantId != \'\'"> AND merchant_id =#{merchantId} </if> <choose> <when test="sidx != null and sidx.trim() != \'\'"> order by ${sidx} ${order} </when> <otherwise> order by id desc </otherwise> </choose>
</select>

 

分类:

技术点:

相关文章:

  • 2021-05-09
  • 2020-07-28
  • 2021-09-16
  • 2021-11-15
  • 2021-12-02
  • 2021-10-31
  • 2018-03-26
  • 2021-04-09
猜你喜欢
  • 2021-09-16
  • 2021-11-08
  • 2021-09-16
  • 2021-10-17
  • 2021-09-16
  • 2021-11-11
  • 2021-04-17
相关资源
相似解决方案