一对一用assosiation用javaType
多对多用的是collection,用的是ofType
一对一
在Cunstomer类中加入Orders orders类型的属性并生产get、set方法
一对多
collection property="orders" ofType="com.yc.m.Orders">
在Cunstomer类中加入List
多对多
public class Course { private Integer id; private String courseCode; // 课程编号 private String courseName;// 课程名称 private List
Course { private Integer id; private String courseCode; // 课程编号 private String courseName;// 课程名称 private Liststudents;// 选课学生 // get/set public Course() {} public Course(Integer id, String courseCode, String courseName) { super(); this.id = id; this.courseCode = courseCode; this.courseName = courseName; } public Course(Integer id, String courseCode, String courseName, List students) { this.id = id; this.courseCode = courseCode; this.courseName = courseName; this.students = students; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getCourseCode() { return courseCode; } public void setCourseCode(String courseCode) { this.courseCode = courseCode; } public String getCourseName() { return courseName; } public void setCourseName(String courseName) { this.courseName = courseName; } public List getStudents() { return students; } public void setStudents(List students) { this.students = students; } @Override public String toString() { return "Course [id=" + id + ", courseCode=" + courseCode + ", courseName=" + courseName + ", students=" + students + "]"; } } students;// 选课学生 // get/set public Course() {} public Course(Integer id, String courseCode, String courseName) { super(); this.id = id; this.courseCode = courseCode; this.courseName = courseName; } public Course(Integer id, String courseCode, String courseName, List students) { this.id = id; this.courseCode = courseCode; this.courseName = courseName; this.students = students; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getCourseCode() { return courseCode; } public void setCourseCode(String courseCode) { this.courseCode = courseCode; } public String getCourseName() { return courseName; } public void setCourseName(String courseName) { this.courseName = courseName; } public List getStudents() { return students; } public void setStudents(List students) { this.students = students; } @Override public String toString() { return "Course [id=" + id + ", courseCode=" + courseCode + ", courseName=" + courseName + ", students=" + students + "]"; } }
public class Student { private Integer id; private String name; // 姓名 private String gender; // 性别 private String major; // 专业 private String grade; // 年级 private List
Student { private Integer id; private String name; // 姓名 private String gender; // 性别 private String major; // 专业 private String grade; // 年级 private Listcourses;// 所选的课程 public Student(Integer id, String name, String gender,String major, String grade, List courses) { super(); this.id = id; this.name = name; this.gender = gender; this.major = major; this.grade = grade; this.courses = courses; } public Student(Integer id, String name, String gender, String major, String grade) { super(); this.id = id; this.name = name; this.gender = gender; this.major = major; this.grade = grade; } public Student() { super(); } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public String getMajor() { return major; } public void setMajor(String major) { this.major = major; } public String getGrade() { return grade; } public void setGrade(String grade) { this.grade = grade; } public List getCourses() { return courses; } public void setCourses(List courses) { this.courses = courses; } @Override public String toString() { return "Student [id=" + id + ", name=" + name + ", gender=" + gender + ", major=" + major + ", grade=" + grade + ", courses=" + courses + "]"; } } courses;// 所选的课程 public Student(Integer id, String name, String gender,String major, String grade, List courses) { super(); this.id = id; this.name = name; this.gender = gender; this.major = major; this.grade = grade; this.courses = courses; } public Student(Integer id, String name, String gender, String major, String grade) { super(); this.id = id; this.name = name; this.gender = gender; this.major = major; this.grade = grade; } public Student() { super(); } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public String getMajor() { return major; } public void setMajor(String major) { this.major = major; } public String getGrade() { return grade; } public void setGrade(String grade) { this.grade = grade; } public List getCourses() { return courses; } public void setCourses(List courses) { this.courses = courses; } @Override public String toString() { return "Student [id=" + id + ", name=" + name + ", gender=" + gender + ", major=" + major + ", grade=" + grade + ", courses=" + courses + "]"; } }
collection property="courses" resultMap="CourseResult">