正常我们写ibatis的sqlmap-mapping-*.xml文件时,传入的参数都用##标识,如下所示:
<resultMap id="personInfo" class="com.bijian.study.dto.PersonDTO"> <result property="name" column="person_name"></result> <result property="age" column="person_age"></result> <result property="sex" column="person_sex"></result> </resultMap> <select id="getPersonListByCodeAndName" parameterClass="java.util.Map" resultMap="personInfo"> SELECT person_name, person_age, person_sex FROM person_info WHERE person_code = #personCode# <isNotEmpty prepend="AND" property="personName"> person_name = #personName# </isNotEmpty> </select>
但对于like,就不能用##,需用$$。如下所示:
<resultMap id="personInfo" class="com.bijian.study.dto.PersonDTO"> <result property="name" column="person_name"></result> <result property="age" column="person_age"></result> <result property="sex" column="person_sex"></result> </resultMap> <select id="getPersonListByName" parameterClass="java.lang.String" resultMap="personInfo"> SELECT person_name, person_age, person_sex FROM person_info WHERE person_name like '%$brandName$%' </select>