为了账号安全,请及时绑定邮箱和手机立即绑定

Mapped Statements collection already contains value for简直了,根本不知道错在哪

Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [H:\JAVA practice\seckill\target\classes\mapper\SecKillDao.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.imooc.seckill.dao.SecKillDao.reduceNumber

at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:484)

at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:355)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)

... 39 more

Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.imooc.seckill.dao.SecKillDao.reduceNumber

at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:120)

at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92)

at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:482)

... 42 more

Caused by: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.imooc.seckill.dao.SecKillDao.reduceNumber

at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:837)

at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:809)

at org.apache.ibatis.session.Configuration.addMappedStatement(Configuration.java:633)

at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:302)

at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:109)

at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:135)

at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:128)

at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:118)

... 44 more


正在回答

5 回答

铁子。看看你的mybatis-config.xml

<mappers>
    <mapper resource="mapper/SeckillDao.xml"/>
</mappers>

这个删掉。和spring-dao 的配置重复了

0 回复 有任何疑惑可以回复我~
#1

慕雪7260907

我是因为这个问题,我真服了,感谢
2023-08-02 回复 有任何疑惑可以回复我~

public interface SecKillDao {
   /**
    * 减库存
    * @param seckillId
    * @param killTime
    * @return 返回值>1,表示表中插入的行数
    */
   int reduceNumber( long seckillId,  Date killTime);

   SecKill queryById(long seckillId);

   /**
    * 查列表,偏移量表示要多少
    * @param offset
    * @param limit
    * @return
    */
   List<SecKill> queryAll(int offset, int limit);
}



0 回复 有任何疑惑可以回复我~

还有SecKillDao也贴一下,reduceNumber的参数有异常。

0 回复 有任何疑惑可以回复我~
#1

光明伟岸的春哥大人 提问者

楼下,SecKillDao的代码
2017-04-30 回复 有任何疑惑可以回复我~

<?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.imooc.seckill.dao.SecKillDao">

   <update id="reduceNumber">
       update
       seckill
       set
         number=number-1
       where
         seckill_id = #{seckillId}
       and start_time <![CDATA[<=]]> #{killTime},
       and end_time >= #{killTime},
       and number>0
   </update>

   <select id="queryById" parameterType="long" resultType="SecKill">
       SELECT seckill_id,name,number,start_time,end_time,create_time
       FROM seckill
       WHERE seckill_id = #{seckillId}
   </select>
   
   <select id="queryAll" resultType="SecKill" >
       SELECT seckill_id,name,number,start_time,end_time,create_time
       FROM seckill
       ORDER BY create_time DESC
       limit #{offset},#{limit}
   </select>
</mapper>

0 回复 有任何疑惑可以回复我~

根据错误提示应该是SecKillDao.xml这个文件解析出错,仔细检查下这个文件,看哪里配置有问题。

0 回复 有任何疑惑可以回复我~
#1

光明伟岸的春哥大人 提问者

楼下有我的SecKillDao.xml,我还是没有找出错在哪里了
2017-04-28 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

Mapped Statements collection already contains value for简直了,根本不知道错在哪

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信