多对一(多个学生对一个老师
疑问:
-
为什么#{}里面写啥都行?#{}就是一个占位符—单条件写啥都可以
public interface TeacherMapper { //通过老师id获取老师信息及对应的学生 Teacher getTeacher( @Param("tid") int tid,@Param("sname") String name ); }
-
为什么加不加@Param(“tid”)都没影响----多用于多条件查询,一个条件没啥影响
<select id="getTeacher" resultMap="TeacherS">
SELECT s.id sid,s.name sname,t.name tname,t.id tid
from student s,teacher t
where t.id=#{tid} and s.name=#{sname}
</select>
<resultMap id="TeacherS" type="teacher">
<result property="name" column="tname"/>
<result property="id" column="tid"/>
<collection property="students" ofType="student">
<result property="name" column="sname"/>
<result property="id" column="sid"/>
<result property="tid" column="tid"/>
</collection>
</resultMap>
</mapper>