mybatis 参数传入,以及#,$占位符区别

 单个的string传递需要@Param否则会报没有get方法,设置不入sql参数(There is no getter for property named 'bz' in 'class java.lang.String')

     map,实体等都会有内置的getter

     public List<TbBasBedSrt> getTbBasBedSrtList(Map<String, Object> map);

   

      public List<?> getbedByBz(@Param(value="_bz") String _bz);

      <select id="getbedByBz" parameterType="string" resultType="java.util.HashMap">

select * from tb_bas_bed_srt where bz like '%${_bz}%' order by order_num 

</select>

   <select id="getTbBasLkpByBusinessTypeMap" parameterType="String"

resultType="java.util.HashMap" >

SELECT * FROM TB_BAS_LKP f

where 1 = 1

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

and f.BUSINESS_TYPE = #{businessType}//不用$,$传递参数的方式不一样,#会将null转化""

</if>

</select>

$的不会转化为string 即不会加'',此时sql会识别此字段为关键字(列名,表名)所以‘$’常常这样用,补单用$

SQL: SELECT * FROM TB_BAS_LKP f   where 1 = 1           and  f.BUSINESS_TYPE = CURRENCY_TYPE_UNIT_RMB

### Cause: java.sql.SQLException: ORA-00904: "CURRENCY_TYPE_UNIT_RMB": 标识符无效

#的会自动把参数转化为string

 Preparing: SELECT * FROM TB_BAS_LKP f where 1 = 1 and f.BUSINESS_TYPE = ? 

 CURRENCY_TYPE_UNIT_RMB(String)

猜你喜欢

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