---
title: "MyBatis中出现Mapped Statements collection does not contain value异常解决方案"
author: "whilew"
date: "2012-05-16T09:08:00Z"
tags: []
slug: "mybatis-mapped-statements-collection-does-not-contain-value"
draft: false
lastmod: "2013-01-13T21:43:51Z"
id: 1769078
url: "https://whilew.iteye.com/blog/1769078"
---

在使用MyBatis实现数据持久层过程中，定义了如下一个&lt;select&gt;

```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.talkweb.mapper.lead.LeadKPIDataMapper">
<resultMap type="com.talkweb.domains.lead.KPIDataVO" id="res_kpiDataVO">
<result property="tagId" column="TAG_ID"/>
<result property="tagName" column="CAL_NAME"/>
<result property="tagValue" column="TAG_VALUE"/>
<result property="tagl1mValue" column="TAG_L1M_VALUE"/>
<result property="tagl1yValue" column="TAG_L1Y_VALUE"/>
<result property="risL1mRat" column="RIS_L1M_RAT"/>
<result property="risL1yRat" column="RIS_L1Y_RAT"/>
<result property="tagNameTip" column="CAL_BUS_DESC"/>
<result property="date" column="TIME_ID"/>
<result property="areaId" column="AREA_ID"/>
<result property="cntyId" column="CNTY_ID"/>
<result property="townId" column="TOWN_ID"/>
</resultMap>

<select id="findKPIData" resultMap="res_kpiDataVO">
SELECT K.TAG_ID,T.CAL_NAME FROM SHW.RPT_MN_TAG_DFLT_FEE_MM AS  K  INNER JOIN  WI.MN_CAL_LIST_DST AS T 
```

```
ON  K.TAG_ID=T.TAG_ID  AND  K.TIME_ID=20120515 AND  K.CNTY_ID='E398' WITH UR
</select>
</mapper>
```

对应的接口文件为LeadKPIDataMapper .java:

```
public interface LeadKPIDataMapper {
public List<KPIDataVO> findKPIData();
}
```

在测试过程中，系统总是出现如下异常：

java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.talkweb.mapper.lead.LeadKPIDataMapper.findKPIData  
at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:594)  
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:436)  
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:428)  
at org.apache.ibatis.binding.MapperMethod.setupCommandType(MapperMethod.java:188)  
at org.apache.ibatis.binding.MapperMethod.&lt;init&gt;(MapperMethod.java:51)  
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:37)

经过排查，解决上述异常的过程如下：

1.确定xml文件中&lt;mapper namespace=""/&gt;中的namespace是否路径正确(在此案例中namespace与实际路径一致)，由于namespace不同会引发此问题

2.确定xml文件的名称是否与接口类的名称保持一致，在上例中出现问题就是因为不小心将xml文件命名为LendKPIDataMapper.xml，而接口文件为:LeadKPIDataMapper.java。一字之差导致异常的发生。

总结：细心，仔细，认真是程序开发之根本。