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)