通过ResultMap标签,在标签里定义Collection标签
1、按查询嵌套处理
实际两条执行sql
<select id="getTeacher2" resultMap="teacherStu2">
select * from teacher where id = #{id}
</select>
<resultMap id="teacherStu2" type="com.me.domain.Teacher2" >
<result property="id" column="id"/>
<result property="name" column="name"/>
<collection property="students" javaType="ArrayList" ofType="com.me.domain.Student2" select="getStudentByTid" column="id"/>
</resultMap>
<select id="getStudentByTid" resultType="com.me.domain.Student2">
select * from student where tid = #{id}
</select>
1、集合--collection【一对多】
2、关联--association【多对一】
3、javaType:用来指定实体类中属性的类型
4、ofType:用来指定映射到List或集合中的实体类型,泛型中的约束类型。
2、按结果嵌套处理(联表查询)
<select id="getTeacher" resultMap="teacherStu">
select s.id sid ,s.name sname ,t.id tid ,t.name tname
from student s, teacher t
where s.tid = t.id and t.id =#{id}
</select>
<resultMap id="teacherStu" type="com.me.domain.Teacher2">
<result property="id" column="tid"/>
<result property="name" column="tname"/>
<collection property="students" ofType="com.me.domain.Student2">
<result property="id" column="sid"/>
<result property="name" column="sname"/>
<result property="tid" column="tid"/>
</collection>
</resultMap>
实际一个查询sql,会有分页问题出现
多条件查询的写法:
column="{id=id,name=name}"
mybatis的内部类用 $
com.shh.multiple.linkage.domain.ControlConfig$ControlConfigOperate