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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM