代码:
<!--查询Source记录,还有Source属于的部门-->
<select id="selectAllSourceAndDepart" resultMap="SourceAndDepart" parameterType="java.lang.Integer">
select *
FROM net_source
JOIN sys_depart ON sys_depart.depart_id = net_source.depart_id
AND sys_depart.depart_stat != 0
<if test="systemId != -1">
</if>
WHERE source_stat != 0
ORDER BY net_source.depart_id
</select>
传入了一个Integer的参数systemId,并且通过if判断。
报错:
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'systemId' in 'class java.lang.Integer'
### Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'systemId' in 'class java.lang.Integer'
错误原因:
if语句中的参数,mybatis将通过反射机制去parameterType里面去调用getter方法得到参数,但是Integer里面,明显没有systemId,所以无法得到。
将parameterType换成一个包含这个参数的实体类,并且拥有getter方法