在idea使用Mybatis框架时,在实现老师与学生的一对多时出现错误
这里是因为
<select id="getTeacher" resultMap="StudentTeacher">
select s.id sid, s.name sname, t.id tid, t.name tname
from mybatis.teacher t,mybatis.student s
where s.tid = t.id and t.id = #{tid}
</select>
<resultMap id="StudentTeacher" type="Teacher">
<result property="id" column="tid"/>
<result property="name" column="tname"/>
<!--复杂的属性,我们需要单独处理
对象:association
集合:collection
javaType="”指定属性的类型!
集合中的泛型信息,我们使用ofType获取
-->
<collection property="student" ofType="Student">
<result property="id" column="sid"/>
<result property="name" column="sname"/>
<result property="tid" column="tid"/>
</collection>
</resultMap>
collection property=“student” ofType=“Student” 中的property的属性值与实体类的没有对应所导致的,将其属性值改为与其实体的属性名相同,即可正常编译。