<resultMap?type="com.xx.xx.Teacher"?id="ResultMap">
????<id?column="teacherId"?property="teacher_id"?jdbcType="BIGINT"?/>
????<result?column="teacherName"?property="teacher_name"?jdbcType="VARCHAR"?/>
????<association?property="studentList"?column="teacher_id"
???select="com.xxxx.selectStudentByTeacherId"></association>
</resultMap>
<resultMap?type="com.xx.xx.Student"?id="StudentResultMap">
????<id?column="teacherId"?property="teacher_id"?jdbcType="BIGINT"?/>
????<result?column="teacherName"?property="teacher_name"?jdbcType="VARCHAR"?/>
????<association?property="studentList"?column="teacher_id"
???select="com.xxxx.selectStudentByTeacherId"></association>
</resultMap>
<select?id="selectTeacherList"?parameterMap="java.util.Map"?resultMap="ResultMap">
?select?*?from?teacher?where?teacher_name?like??CONCAT(CONCAT('%',
#{teacherName}),'%')
</select>
<select?id="selectTeacherList"?parameterType="java.lang.Long"?resultMap="StudentResultMap">
?select?*?from?student?where?teacher_id?=?#{teacherId}
</select>
public?class?Teacher{
????private?Long?teacherId;
????private?String?teacherName;
????private?List<Student>?studentList;
????//get?and?set?method
}
public?class?Student{
????private?Long?studentId;
????private?String?studentName;
????//get?and?set?method
}
这样?会查出来?这样的结果JSON
[{
"teacherId":"1",
"teacherName":"张三",
"studentList":[
???????????????{"studentName":"a学生"},
???????????????{"studentName":"b学生"}
???????????????]
?},{
"teacherId":"2",
"teacherName":"张四",
"studentList":[
???????????????{"studentName":"c学生"},
???????????????{"studentName":"d学生"}
???????????????]
?}]
?一般这样集联查询的多
用户登录
还没有账号?立即注册
用户注册
投稿取消
文章分类: |
|
还能输入300字
上传中....