Mybatis:Mapped Statements collection does not contain value for

bug:使用Mybatis时,报错;

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mycom.mapping.SampleMapper.selectByPrimaryKey
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mycom.mapping.SampleMapper.selectByPrimaryKey
     at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:111)
     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)
     at mycom.test.mybatis.test.MybatisTest.main(MybatisTest.java:43)
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mycom.mapping.SampleMapper.selectByPrimaryKey
     at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:797)
     at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:631)
     at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:624)
     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107)
     ... 3 more

原因:以下映射sql的标识字符串和Samplemapper.xml中的namespace()不一致;之前都是手写的namespace,命名的时候,使用的是mapper.xml的目录,这次是用工具自动生成的mapper.xml,namespace命名是用的dao目录;

        String statement2 = "mycom.mapping.SampleMapper.selectByPrimaryKey";//映射sql的标识字符串
        Sample result = session.selectOne(statement2, 2);
        System.out.println(result);

你可能感兴趣的:(Java,Mybatis,sql,ssm)