在<select>标签中, parameterType 传递基本数据类型的时候,可以给参数取任意的名字,
如此处可以用#{id}, #{abc}, #{xxx}都可以。
但是当使用<if>判断 test 条件的时候,就需要使用_parameter 作为参数名,如:
<select id="getDeptById" parameterType="int" resultMap="deptMap">
select ID,NAME from DEPT
<if test="_parameter!=null"> where ID=#{id}</if>
</select>
如果写成下面的形式,就会报错:
<select id="getDeptById" parameterType="int" resultMap="deptMap">
select ID,NAME from DEPT
<if test="id!=null"> where ID=#{id}</if>
</select>
报错如下:
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: There is
no getter for property named 'id' in 'class java.lang.Integer'
### Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property
named 'id' in 'class java.lang.Integer'