报错信息:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.UnsupportedOperationException
### The error may exist in file [C:\Users\5618\IdeaProjects\easy-home\eh-my-dao\target\classes\sqlmaps\mybatis\DepartmentUser.xml]
### The error may involve com.xgt.dao.mybatis.department.DepartmentUserDao.queryDepartmentUserIdByUserId
### The error occurred while handling results
### SQL: SELECT user_id FROM yp_department_user WHERE department_id = (SELECT department_id FROM yp_department_user WHERE user_id = ?)
### Cause: java.lang.UnsupportedOperationException
Dao层方法:
List<Integer> queryDepartmentUserIdByUserId(Integer loginAdminUserId);
xml文件sql写法:
<select id="queryDepartmentUserIdByUserId" parameterType="java.lang.Integer" resultType="java.util.List"> SELECT user_id FROM yp_department_user WHERE department_id = (SELECT department_id FROM yp_department_user WHERE user_id = #{loginAdminUserId}) </select>
分析错误地方:
接收传参:parameterType="java.lang.Integer"没有问题,
返回参数:resultType="java.util.List"看上去很合理,但是错就错在这里,
解决办法:将java.util.List改为Integer。
总结:
原因就在于resultType代表的是List中的元素类型,而不应该是List本身,究其原因就在于被dao中的方法声明(标记处)
List<Integer> queryDepartmentUserIdByUserId(Integer loginAdminUserId);
给迷惑住了
切记:resultType返回的是集合中的元素类型,而不是集合本身