反射练习错误nested exception is Expected one result (or null) to be returned by selectOne(), but found: 20

反射练习错误nested exception is Expected one result (or null) to be returned by selectOne(), but found: 20练习反射的时候获取数据库中数据,直接报错了

mapper.xml配置文件是这样婶的

反射练习错误nested exception is Expected one result (or null) to be returned by selectOne(), but found: 20

将数据直接存在map中,这样我再使用反射获取数据

错误原因,多条数据返回的是list类型,但是我给自定义返回的是Map,这样就可以练习自己的反射

解决方法:查询某一条数据,或者返回结果为List

如果必须要返回时Map,像我一样要用Map就将map放在list中  如 List<Map<String ,Object>>

 

反射练习错误nested exception is Expected one result (or null) to be returned by selectOne(), but found: 20