mybatis实现动态字段查询,如果某个条件为null,则不查询某个字段,否则就查询某个字段

 

先看一下 怎么实现动态的自定义字段查询:

例如:

而field 就是数据表中的某一个字段

String findContextByGoodsUid(@Param("goodsUid") String goodsUid,@Param("field") String field);

 

<select id="findContextByGoodsUid" resultType="java.lang.String" parameterType="java.lang.String">
        SELECT
        ${field}
        FROM goods_config_query
        WHERE goods_uid = #{goodsUid}
    </select>

 

同样 如果某个字段为null,则不查询某个字段

<select id="findContextAndNoActByGoodsUid" resultType="com.pisen.cloud.luna.ms.goods.api.beans.MemberQueryBean" parameterType="java.lang.String">
        SELECT
        <if test="field != null">
            ${field} context,
        </if>
        not_act notAct,
        scan_code_limit_time scanCodeLimitTime,
        scan_code_limit scanCodeLimit
        FROM goods_config_query
        WHERE goods_uid = #{goodsUid}
    </select>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-09
  • 2021-07-02
  • 2022-12-23
  • 2021-06-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案