原始代碼:
查不到
SELECT
b.ID,
b.PRICE_ITEM_CODE,
b.PRICE_NAME,
b.DES_SITE_CODE,
b.SRC_SITE_CODE,
b.CALC_TYPE,
b.BIZ_TYPE,
b.CACULATE_MODE,
b.PRODUCT_CODE,
b.PRODUCT_EFFECT,
b.DIS_TYPE,
b.START_DATE,
b.END_DATE,
b.CREATE_DATE,
b.MODIFY_DATE,
b.CREATE_USER_CODE,
b.MODIFY_USER_CODE,
b.AUDIT_STATUS,
b.AUDIT_USER_CODE,
b.AUDIT_DATE,
b.AUDIT_OPINION,
b.RELE_SITE_CODE,
b.REMARKS,
b.AUDIT_KINDS,
b.OFFER_STATUS
FROM
T_FOMF_SUPPER_PRICE_MAIN_AD b
WHERE
1=1
<!-- AND b.PRICE_ITEM_CODE = '557' 寫死可以查到 -->
<!-- 計費類型 -->
<trim></trim>
<if test="priceItemCode != null and priceItemCode !=''" >
AND b.PRICE_ITEM_CODE = #{priceItemCode,jdbcType=VARCHAR}
</if>
問題所在:PRICE_ITEM_CODE 字段的類型為 CHAR(5)導致
由於不滿足5個長度會自動補,導致查不到。
解決方式: 加trim
SELECT
b.ID,
b.PRICE_ITEM_CODE,
b.PRICE_NAME,
b.DES_SITE_CODE,
b.SRC_SITE_CODE,
b.CALC_TYPE,
b.BIZ_TYPE,
b.CACULATE_MODE,
b.PRODUCT_CODE,
b.PRODUCT_EFFECT,
b.DIS_TYPE,
b.START_DATE,
b.END_DATE,
b.CREATE_DATE,
b.MODIFY_DATE,
b.CREATE_USER_CODE,
b.MODIFY_USER_CODE,
b.AUDIT_STATUS,
b.AUDIT_USER_CODE,
b.AUDIT_DATE,
b.AUDIT_OPINION,
b.RELE_SITE_CODE,
b.REMARKS,
b.AUDIT_KINDS,
b.OFFER_STATUS
FROM
T_FOMF_SUPPER_PRICE_MAIN_AD b
WHERE
1=1
<!-- AND b.PRICE_ITEM_CODE = '557' -->
<!-- 計費類型 -->
<if test="priceItemCode != null and priceItemCode !=''" >
AND trim(b.PRICE_ITEM_CODE) = #{priceItemCode,jdbcType=VARCHAR}
</if>
