完整异常信息:
org.mybatis.spring.MyBatisSystemException: nested exception is
org.apache.ibatis.reflection.ReflectionException:
There is no getter for property named 'userId' in 'class java.lang.Integer'
产生场景:
List<UserRole> selectSalesmanRoleByUserId(Integer userId);
<select id="selectSalesmanRoleByUserId" resultType="...">
SELECT
...
AND user_id = ${userId}
</select>
这个问题产生是因为Mybatis单个参数使用${}作为占位符时必须使用@Param注解标注参数
解决方法:
1.加上@Param(“userId”)注解
List<UserRole> selectSalesmanRoleByUserId(@Param("userId") Integer userId);
2.将xml文件中占位符修改为#{}
<select id="selectSalesmanRoleByUserId" resultType="...">
SELECT
...
AND user_id = #{userId}
</select>