mybatis 占位符$ 与#区别

<select id="getTbCusFirmChgAry" parameterType="map" resultMap="BaseResultMapVo">

  select C.* from TB_CUS_FIRM_CHG C 

  where 1=1

  <if test="sCustomerID!=null and sCustomerID!=''">

   and lower(C.CUSTOMER_ID) like '%${sCustomerID}%'

  </if>

<if test="comp_type!=null and comp_type!=''">

     and C.COMP_TYPE =#{comp_type}

  </if>

</select>

=======sql语句如下========

Preparing: SELECT count(*) FROM TB_CUS_FIRM_CHG C WHERE 1 = 1 AND lower(C.CUSTOMER_ID) LIKE '%e00000005%' AND C.COMP_TYPE = ? 

Parameters: B(String)

$直接嵌sql中,#以参数的形式传入

此中B如果用$直接传入 LIKE '%e00000005%' AND C.COMP_TYPE =B

数据库会报找不到B错误。  ORA-00904: "B": 标识符无效

 lower(C.CUSTOMER_ID)  :lower函数的意义是把数据库中此字段的值全部变为小写

猜你喜欢

转载自yuhuiblog6338999322098842.iteye.com/blog/2306120