接上一篇,这一次,只讲嵌套结果,同样是上一次的三张表 上次忘了介绍 resultMap,补上: resultMap概念视图
这次的查询要求是:
t.teacherId =c.teacherId join student s on s.classId=c.clsId
1. 我们来看三个 Mapper.xml的配置
=======></mapper>======></mapper>=======>==”TeacherMap”>select * from teacher t join classes c on t.teacherId =#{teacherId} and t.teacherId =c.teacherIdjoin student s on s.classId=c.clsId</select></mapper>
2. mybatis.xml
=>=========> > ==>
3. 接口
4. 测试类
package test;import org.junit.After;import org.junit.Before;import org.junit.Test;import com.yc.mybatis.mapper.TeacherMapper;import com.yc.mybitis.entity.Teacher;import com.yc.mybitis.util.MybatisUtil;{private TeacherMapper tMapper;() throws Exception {tMapper=MybatisUtil.getSession().getMapper(TeacherMapper.class);}() throws Exception {tMapper=null;}() {Teacher t=tMapper.getTeacherById(5001);System.out.println( t );}}
5. 测试结果
好了,嵌套结果告一段落。 mybatis 讲解怎么配置和使用,并没有了解底层实现,,有兴趣的大家可以找找资料。
知已知彼,百战百胜。