The mybatis parameter is passed in, and the difference between # and $ placeholders

 A single string transmission requires @Param, otherwise it will report that there is no get method, and the sql parameter cannot be set (There is no getter for property named 'bz' in 'class java.lang.String')

     Maps, entities, etc. will have built-in getters

     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}//The way of passing parameters without $,$ is different, #will convert null to ""

</if>

</select>

 

$ will not be converted to string, that is, it will not be added with ''. At this time, sql will recognize this field as a keyword (column name, table name), so '$' is often used in this way, and $ is used for supplementary orders.

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": invalid identifier

 

# will automatically convert the parameters to strings

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

 CURRENCY_TYPE_UNIT_RMB(String)

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326653658&siteId=291194637