mybatis class tests have shown that the implementation of test07 test05 test class calls the sql statement error

1 Test class 
@Test 
public  void TEST07 () 
{ 
    IStudentDao StudentDAO = new new IStudentDaoImpl (); 
    Student Student = studentDao.selectStudentById (10 ); 
    System.out.println ( "lookup is successful!" ); 
    System.out.println (Student .toString ()); 
}
2.IStudentDao接口
@Override
public Student selectStudentById(int id) {
    SqlSession sqlSession = null;
    try {
        sqlSession = MySqlSession.getSqlSession();
        Student student = sqlSession.selectOne("selectId",id);
        return student;
    } catch (IOException e) {
        e.printStackTrace();
    }finally {
        if(sqlSession!=null){
            sqlSession.close();
        }
    }
    return null;
}
3.mapper.xml
...
<select id="selectAll" resultType="com.abc.beans.Student"> select * from student </select> <!--根据姓名查询全部学生信息Map --> <select id="selectAll" resultType="com.abc.beans.Student" parameterType="String"> select * from student where name = #{name} </select> <select id="selectId" resultType="com.abc.beans.Student"> select * from student where id = #{id} </select>
...

Problem, call test07 test, using a

<select id="selectId"  resultType="com.abc.beans.Student">
    select * from student where id = #{id}
</select>

But the error is selectAll side of the problem, and finally found himself written two careless Id named selectAll

Error message:

org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in com/abc/dao/IStudentDao.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'com/abc/dao/IStudentDao.xml'. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for org.mybatis.example.BlogMapper.selectAll
 at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
 at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)
 at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:36)
 at com.abc.utils.MySqlSession.getSqlSession(MySqlSession.java:16)
 at com.abc.dao.IStudentDaoImpl.selectStudentById(IStudentDaoImpl.java:132)
 at com.abc.AppTest.test07(AppTest.java:90)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
 at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
 at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
 at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
 at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
 at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
 at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
 at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'com/abc/dao/IStudentDao.xml'. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for org.mybatis.example.BlogMapper.selectAll
 at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121)
 at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:99)
 at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:50)
 ... 26 more
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'com/abc/dao/IStudentDao.xml'. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for org.mybatis.example.BlogMapper.selectAll
 at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:120)
 at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92)
 at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:373)
 at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:119)
 ... 28 more
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for org.mybatis.example.BlogMapper.selectAll
 at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:872)
 at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:844)
 at org.apache.ibatis.session.Configuration.addMappedStatement(Configuration.java:668)
 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)
 ... 31 more

 

Guess you like

Origin www.cnblogs.com/hyjh/p/11865363.html