MyBatis中出现Mapped Statements collection does not contain value异常解决方案

来源:互联网 发布:php项目架构设计文档 编辑:程序博客网 时间:2024/06/14 14:19

在使用MyBatis实现数据持久层过程中,定义了如下一个<select>

[html] view plaincopyprint?
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4. <mapper namespace="com.talkweb.mapper.lead.LeadKPIDataMapper">
  5. <resultMaptype="com.talkweb.domains.lead.KPIDataVO"id="res_kpiDataVO">
  6. <result property="tagId" column="TAG_ID"/>
  7. <result property="tagName" column="CAL_NAME"/>
  8. <result property="tagValue" column="TAG_VALUE"/>
  9. <result property="tagl1mValue" column="TAG_L1M_VALUE"/>
  10. <result property="tagl1yValue" column="TAG_L1Y_VALUE"/>
  11. <result property="risL1mRat" column="RIS_L1M_RAT"/>
  12. <result property="risL1yRat" column="RIS_L1Y_RAT"/>
  13. <result property="tagNameTip" column="CAL_BUS_DESC"/>
  14. <result property="date" column="TIME_ID"/>
  15. <result property="areaId" column="AREA_ID"/>
  16. <result property="cntyId" column="CNTY_ID"/>
  17. <result property="townId" column="TOWN_ID"/>
  18. </resultMap>
  19. <select id="findKPIData" resultMap="res_kpiDataVO">
  20. 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
[html] view plaincopyprint?
  1. ON K.TAG_ID=T.TAG_ID ANDK.TIME_ID=20120515 ANDK.CNTY_ID='E398' WITH UR
  2. </select>
  3. </mapper>


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

[java] view plaincopyprint?
  1. public interface LeadKPIDataMapper {
  2. public List<KPIDataVO> findKPIData();
  3. }


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

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.<init>(MapperMethod.java:51)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:37)

经过排查,解决上述异常的过程如下:

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

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

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


【原文:http://blog.csdn.net/wikiwang/article/details/7571108】

0 0
原创粉丝点击