spring 整合Mybatis 错误:A query was run and no Result Maps were found for the Mapped Statement 'com.xxhh.mapper.XxhhTableBabyCustomMapper.selectAllBaby'. It's likely that neither a Result Type nor a Resul
运行环境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+ eclipse
错误:A query was run and no Result Maps were found for the Mapped Statement......
错误原因:在使用springmvc+mybatis时候自定义mapper查询数据是提示以下错误
解决办法:最后查询出在我的自定义mapper中没有写查询的返回类型也就是"resultType"每个查询都会返回个结果集,我们需要让系统知道返回什么样的结果集,导致出现下面问题
错误代码:
[org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] - Resolving exception from handler [public java.util.Map<java.lang.String, java.lang.Object> com.xxhh.controller.BabyController.selectAllBaby()]: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'com.xxhh.mapper.XxhhTableBabyCustomMapper.selectAllBaby'. It's likely that neither a Result Type nor a Result Map was specified. [org.springframework.web.servlet.DispatcherServlet] - Could not complete request org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'com.xxhh.mapper.XxhhTableBabyCustomMapper.selectAllBaby'. It's likely that neither a Result Type nor a Result Map was specified. at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365) at com.sun.proxy.$Proxy15.selectList(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:195) at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) at com.sun.proxy.$Proxy20.selectAllBaby(Unknown Source)
相关代码:
自定义mapper
<!-- 查询所有的宝贝 --> <select id="selectAllBaby" resultType="com.xxhh.po.XxhhTableBaby"> SELECT * FROM xxhh_table_baby </select>