今天编辑mybatis的xml文件完成之后,运行时出现如下错误:
[A query was run and no Result Maps were found for the Mapped Statement '***'. It's likely that neither a Result Type nor a Result Map was specified.
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:76) ~[mybatis-spring-1.2.3.jar:1.2.3]
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399) ~[mybatis-spring-1.2.3.jar:1.2.3]
at com.sun.proxy.$Proxy54.selectList(Unknown Source) ~[?:?]
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:205) ~[mybatis-spring-1.2.3.jar:1.2.3]………………
仔细查看mybatis的配置文件,发现遗漏一个属性:resultType
报错的配置是:<select id="selectAllUser" resultMap="BaseResultMap">
而我上面配置的BaseResultMap中不包含我所查询到的所有结果项,
可以这样配置<select id="selectAllUser" resultType="java.util.Map">
最后总结下,就是mybatis中的所有查询,都必须返回resultType或者resultMap的值,否则就会报如上错误的。