Java-EE-SpringMVC与MyBatis企业开发实战-11-MyBatis高级课件.pptx
- 【下载声明】
1. 本站全部试题类文档,若标题没写含答案,则无答案;标题注明含答案的文档,主观题也可能无答案。请谨慎下单,一旦售出,不予退换。
2. 本站全部PPT文档均不含视频和音频,PPT中出现的音频或视频标识(或文字)仅表示流程,实际无音频或视频文件。请谨慎下单,一旦售出,不予退换。
3. 本页资料《Java-EE-SpringMVC与MyBatis企业开发实战-11-MyBatis高级课件.pptx》由用户(三亚风情)主动上传,其收益全归该用户。163文库仅提供信息存储空间,仅对该用户上传内容的表现方式做保护处理,对上传内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知163文库(点击联系客服),我们立即给予删除!
4. 请根据预览情况,自愿下载本文。本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
5. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007及以上版本和PDF阅读器,压缩文件请下载最新的WinRAR软件解压。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java EE SpringMVC MyBatis 企业 开发 实战 11 高级 课件
- 资源描述:
-
1、SpringMVC与MyBatis企业开发实战第十一章 MyBatis框架-高级使用实体之间的关联映射q 数据库实体间有三种对应关系:一对一,一对多,多对多。q 一对一关系:一个学生对应一个学生档案。q 一对多关系:一个员工只属于一个部门,但是一个部门有多名员工。q 多对多关系:一个订单中可以包含多件商品,而一件商品也可以出现在多个订单中。一对多的关系实体类package org.newboy.entity;import java.sql.Date;/*员工实体类*author NewBoy*/public class Employee private int id;/编号private St
2、ring name;/姓名private boolean gender;/性别private Date birthday;/生日,使用的是java.sql.Dateprivate Depart depart;/所在部门对象,指定多对一的关联对象Overridepublic String toString()return Employee id=+id+,name=+name+,gender=+gender+,birthday=+birthday+;/省略了getter和setter方法部门的映射配置文件 select*from depart where depart_id=#departId
3、员工的实体配置文件 select*from employee where depart_id=#departId 测试类/*查询某个部门的所有员工,同时输出部门的名字*/Testpublic void testFindEmployees()/第1个参数:指定映射文件中的命名空间和查询id,第2个参数是部门的idList list=sqlSession.selectList(org.newboy.dao.EmployeeDao.selectEmployees,1);for(Employee employee:list)System.out.println(姓名:+employee.getName
4、()+,生日:+employee.getBirthday()+,部门名:+employee.getDepart().getDepartName();一方的配置q 查询所有的部门信息,并且通过关联得到这个部门下所有的员工,一个部门对象中包含一组员工的集合public class Depart private int departId;private String departName;private String description;private List employees;public List getEmployees()return employees;public void se
5、tEmployees(List employees)this.employees=employees;/省略getter/setter方法配置文件select*from depart where depart_id=#departId select*from depart测试类Testpublic void testFindDeparts()List list=sqlSession.selectList(org.newboy.dao.DepartDao.selectAllDeparts);for(Depart depart:list)System.out.println(部门名:+depart
6、.getDepartName();System.out.println(-);/得到这个部门下所有的员工List employees=depart.getEmployees();for(Employee employee:employees)System.out.println(employee);多对多的关系实体类public class Student private int id;private String stuName;/姓名private Set courses;/所选课程集合Overridepublic String toString()return Student id=+i
7、d+,stuName=+stuName+,courses=+courses+;/省略getter和setter方法public class Course private int id;private String courseName;/课程名private Set students;/选择这门课程的学生集合Overridepublic String toString()return Course id=+id+,courseName=+courseName+,students=+students+;/省略getter和setter方法学生映射文件 select*from student wh
8、ere id=#id select s.*from student s inner join student_course sc inner join course c on s.id=sc.student_id and c.id=sc.course_id where c.id=#id;课程映射文件 select c.*from student s inner join student_course sc inner join course c on s.id=sc.student_id and c.id=sc.course_id where s.id=#id select*from cour
9、se where id=#id 测试类/*查询指定学生所学的课程 */Test public void testFindStudent()/得到1号学生 Student s1=sqlSession.selectOne(org.newboy.dao.StudentDao.findStudentById,1);System.out.println(学生:+s1.getStuName();System.out.println(课程:);/输出1号学生所学的课程 Set courses1=s1.getCourses();for(Course course:courses1)System.out.pri
10、ntln(course.getCourseName();/得到2号学生 Student s2=sqlSession.selectOne(org.newboy.dao.StudentDao.findStudentById,2);System.out.println(学生:+s2.getStuName();System.out.println(课程:);/输出2号学生所学的课程 Set courses2=s2.getCourses();for(Course course:courses2)System.out.println(course.getCourseName();/*查询学习某门课程的学生
展开阅读全文
链接地址:https://www.163wenku.com/p-3372357.html