【mybatis】mybatis自定義動態字段查詢,mybatis實現動態字段查詢,如果某個條件為null,則不查詢某個字段,否則就查詢某個字段


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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM