老师onetomany和manytoone报的都是一个错,没找到

老师onetomany和manytoone报的都是一个错,没找到

"C:\Program Files\Java\jdk1.8.0\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.1\lib\idea_rt.jar=53991:C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.1\lib\idea_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.1\plugins\junit\lib\junit5-rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.1\plugins\junit\lib\junit-rt.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0\jre\lib\rt.jar;C:\Users\86191\IdeaProjects\practice\target\test-classes;C:\Users\86191\IdeaProjects\practice\target\classes;C:\Users\86191\.m2\repository\org\mybatis\mybatis\3.5.1\mybatis-3.5.1.jar;C:\Users\86191\.m2\repository\mysql\mysql-connector-java\5.1.47\mysql-connector-java-5.1.47.jar;C:\Users\86191\.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\86191\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 MyBatisUtilsTestor,testOneToMany


java.lang.ExceptionInInitializerError

at MyBatisUtilsTestor.testOneToMany(MyBatisUtilsTestor.java:110)

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:483)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

at org.junit.runner.JUnitCore.run(JUnitCore.java:137)

at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)

at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)

at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)

at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

Caused by: org.apache.ibatis.exceptions.PersistenceException: 

### Error building SqlSession.

### The error may exist in mapper/classroom.xml

### The error occurred while processing mapper_resultMap[rmClassroom]

### 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 'mapper/classroom.xml'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for classroom.rmClassroom

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 utils.MyBatisUtils.<clinit>(MyBatisUtils.java:19)

... 23 more

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 'mapper/classroom.xml'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for classroom.rmClassroom

at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121)

at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:98)

at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:50)

... 25 more

Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'mapper/classroom.xml'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for classroom.rmClassroom

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

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

at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:373)

at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:119)

... 27 more

Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for classroom.rmClassroom

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

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

at org.apache.ibatis.session.Configuration.addResultMap(Configuration.java:644)

at org.apache.ibatis.builder.MapperBuilderAssistant.addResultMap(MapperBuilderAssistant.java:208)

at org.apache.ibatis.builder.ResultMapResolver.resolve(ResultMapResolver.java:47)

at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:289)

at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:253)

at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java:245)

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

... 30 more

相关代码:

<?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="classroom">
<resultMap id="rmClassroom" type="entity.Classroom">
<id column="classno" property="classNo"/>
<id column="name" property="className"/>
</resultMap>
<select id="selectByclassno" parameterType="String" resultType="entity.Classroom" resultMap="rmClassroom">
select *
from class
where classno = #{VALUE}
</select>
<resultMap id="rmClassroom" type="entity.Classroom">
<id column="classno" property="classNo"></id>
<collection property="student" select="selectByclassno" column="classno"></collection>
</resultMap>
<select id="selectOneToMany" resultMap="rmClassroom">
select *
from class
</select>


</mapper>

相关代码:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<environments default="dev">
<environment id="dev">
<transactionManager type="JDBC"></transactionManager>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://Localhost:3306/babytun?>useUnicode=true&amp;characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="zlz2000714"/>
</dataSource>

</environment>
</environments>
<mappers>
<mapper resource="mapper/student.xml"/>
<mapper resource="mapper/classroom.xml"/>
</mappers>
</configuration>


相关代码:

package entity;

import java.util.List;

public class Classroom {
private Integer id;
private String classNo;
private String className;
private String major;
private List<Student> list;

public List<Student> getList() {
return list;
}

public void setList(List<Student> list) {
this.list = list;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getClassNo() {
return classNo;
}

public void setClassNo(String classNo) {
this.classNo = classNo;
}

public String getClassName() {
return className;
}

public void setClassName(String className) {
this.className = className;
}

public String getMajor() {
return major;
}

public void setMajor(String major) {
this.major = major;
}
}


相关代码:

<?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="student">
<select id="selectAll" resultType="entity.Student">
select *
from student
order by id desc limit 4
</select>

<insert id="insert" parameterType="entity.Student">
INSERT INTO student(id, reg_no, name, sex, age, grade, major)
VALUES (#{id}, #{reg_no}, #{name}, #{sex}, #{age}, #{grade}, #{major})
</insert>
<select id="dynamicSQL" parameterType="java.util.Map" resultType="entity.Student">
select * from student
<where>
<if test="age!=null">
and age &gt;#{age}
</if>
<if test="sex!=null">
and sex=#{sex}
</if>
</where>
</select>

<select id="selectByclassno" parameterType="String" resultType="entity.Student">
select *
from student
where calssno = #{VALUE }
</select>
<resultMap id="rmStudent" type="entity.Student">
<id column="classno" property="classNo"/>
<association property="classroom" select="selectByclassno" column="classno"></association>
</resultMap>
<select id="ManyToOne" resultMap="rmStudent">
select *
from student
</select>
</mapper>


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕小小 2021-09-23 13:35:49

同学你好,建议将全部的代码上传至问答区,便于老师测试定位问题并准确快速的给予同学答复。

祝学习愉快~

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师