mybaits中if 多个test 和 if else 分支支持

mybaits中if 多个test

 

 <select id="selectByDynamicallyWithPage" parameterType="map" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from gene_polymorphism
    <where>
      diag_id = #{conds.diagId,jdbcType=INTEGER}
      <if test="conds.chromesome!=null and conds.chromesome!=''">
        and chromesome = #{conds.chromesome,jdbcType=VARCHAR}
      </if>
      <if test="conds.startPos!=null">
        and start_pos &gt;= #{conds.startPos,jdbcType=BIGINT}
      </if>
    </where>
</select>

 

if else分支:

 

<select id="selectByDynamicallyWithPage" parameterType="map" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from gene_polymorphism
    <where>
      diag_id = #{conds.diagId,jdbcType=INTEGER}
      <if test="conds.chromesome!=null">
        and chromesome = #{conds.chromesome,jdbcType=VARCHAR}
      </if>
      <if test="conds.startPos!=null">
        and start_pos &gt;= #{conds.startPos,jdbcType=BIGINT}
      </if>
      <if test="conds.endPos!=null">
        and end_pos &lt;= #{conds.endPos,jdbcType=BIGINT}
      </if>
      <if test="conds.geneTypes!=null">
        <!--and gene_type in-->
        <!--<foreach collection="conds.geneTypes" open="(" close=")" item="item" separator="," >-->
          <!--#{item,jdbcType=VARCHAR}-->
        <!--</foreach>-->
        and (
        <foreach collection="conds.geneTypes" item="item" separator="or">
          gene_type like CONCAT('%',CONCAT(#{item,jdbcType=VARCHAR}, '%'))
        </foreach>
        )
      </if>
      <if test="conds.geneChange!=null">
        and gene_change like CONCAT('%',CONCAT(#{conds.geneChange,jdbcType=VARCHAR}, '%'))
      </if>
    </where>
    order by
    <trim suffixOverrides=",">
      <choose>
        <when test="conds.chromesomeSort!=null and conds.chromesomeSort=='asc'">
          chromesome asc ,
        </when>
        <when test="conds.chromesomeSort!=null and conds.chromesomeSort=='desc'">
          chromesome desc ,
        </when>
      </choose>
      <choose>
        <when test="conds.startPosSort!=null and conds.startPosSort=='asc'">
           start_pos asc ,
        </when>
        <when test="conds.startPosSort!=null and conds.startPosSort=='desc'">
           start_pos desc ,
        </when>
        <otherwise>
          id desc
        </otherwise>
      </choose>
    </trim>
      limit #{startRow,jdbcType=INTEGER} ,#{pageSize,jdbcType=INTEGER}
  <!--  order by id desc limit #{startRow,jdbcType=INTEGER} ,#{pageSize,jdbcType=INTEGER} -->
  </select>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值