栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

问题记录-A query was run and no Result Maps were found for the Mapped Statement..

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

问题记录-A query was run and no Result Maps were found for the Mapped Statement..

A query was run and no Result Maps were found for the Mapped Statement…

1.报错信息

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 'xxx'.  It's likely that neither a Result Type nor a Result Map was specified.

2.问题分析
由报错信息可知: 很可能既没有指定结果类型, 也没有指定结果映射。
检查mapper.xml文件后, 发现遗漏了里面一个属性resultType=" " 或者 resultMap=" "


    select 
    from discuss_post
    where status != 2
    
        and user_id = #{userId}
    
    order by type desc, create_time desc
    limit #{offset}, #{limit}

MyBatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMap,resultType是直接表示返回类型的,而resultMap则是对外部ResultMap的引用,但是resultType跟resultMap不能同时存在.
(在学习中,有某位老师说: 如果查询sql返回类型是java自带类型,可以自动检测到,那么就可以省略不写这个属性. 呃…个人试了一下会报错,不知道为什么这个老师会这么认为)
3.解决方法
在< select >标签上加上属性resultType=" "即可


在resultType=“DiscussPost”中,DiscussPost就是自定义的POJO,此时可以使用全限定类名 (全限定类名:就是类名全称,带包路径的用点隔开,例如: java.lang.String) 来指定这些POJO的引用.
但这里resultType没写全是因为在配置文件使用mybatis.type-aliases-package来指定POJO扫描包来让mybatis自动扫描到自定义的POJO。

mybatis.type-aliases-package=com.example.demo.entity
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/719967.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号