原始代码: 查不到 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>