Could not find result map XXX 的几种原因?

1 Could not find result map 'XXX'

此错误意为没有找到返回类型resultMap的定义,导致出现这种错误可能会有以下几种原因 ~

一、当查询得到的列名和pojo中定义的属性名不一致,则需要定义resultMap设置列名和属性名之间的映射关系。

 顾名思义,当我们定义了resultMap映射,查询标签中输出参数应该使用resultMap属性,当resultMap属性没有引用到定义的resultMap时,会出现这个问题,代码如下:

定义的resultMap
1 <resultMap type="user" id="userResultMap">
2     <id column="identity" property="id">
3     <result column="name" property="username"/>
4 </resultMap>
引用resultMap
1 <select id="findUserList" parameterType="java.lang.Integer" 
2 resultMap="userResultMapssss">
3     select id identity, username name from user where id = #{id}
4 </select>

二、当没有定义resultMap时,输出参数类型为pojo类。

此时查询标签中输出参数应该使用resultType属性,属性值为定义的pojo类路径,代码如下:

1 <select id="findUserList" parameterType="java.lang.Integer" 
2 resultMap="com.it.po.userQuery"> 没有定义resultMap时,应该使用"resultType"属性,而不能使用resultMap
3     select id identity, username name from user where id = #{id}
4 </select>

三、当没有没有定义resultMap,输出参数类型为pojo类

查询标签中输出参数使用的是resultType属性,但是属性值填写的pojo类路径错误,代码如下

 1 package com.it.po;
 2 
 3 /**
 4  * pojo类
 5  */
 6 public class UserQuery {
 7 
 8     private int id;
 9     private String username;
10     
11     public int getId() {
12         return id;
13     }
14     public void setId(int id) {
15         this.id = id;
16     }
17     public String getUsername() {
18         return username;
19     }
20     public void setUsername(String username) {
21         this.username = username;
22     }
23 }
24 
25 
26 <select id="findUserList" parameterType="java.lang.Integer" 
27 resultMap="com.it.po.userQuerysss"> 
28      select id identity, username name from user where id = #{id}
29 </select>

原文链接:https://www.cnblogs.com/bianxcArticle/p/12238701.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值