ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2020-01-28 20:02:57  阅读:521  来源: 互联网

标签:username map 定义 Could XXX resultMap pojo id 属性


 

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>

 

标签:username,map,定义,Could,XXX,resultMap,pojo,id,属性
来源: https://www.cnblogs.com/bianxcArticle/p/12238701.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有