mybatis實現動態字段查詢,若是某個條件爲null,則不查詢某個字段,不然就查詢某個字段java
先看一下 怎麼實現動態的自定義字段查詢:api
例如:mybatis
而field 就是數據表中的某一個字段ui
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,則不查詢某個字段spa
<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>