使用Mybatis 如何实现多对一或一对多的关联查询?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
成都创新互联公司主要从事网站制作、成都网站设计、网页设计、企业做网站、公司建网站等业务。立足成都服务赣榆,10多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792首先 数据库量表之间字段关系(没有主外键)
studentmajor表的id字段对应student表里major字段
两个实体类
package com.model; import java.util.Date; public class Student { private Integer sno; private String sname; private String ssex; private Integer sclass; private StudentMajor studentmajor; public Student() { super(); } public Student(Integer sno, String sname, String ssex, Integer sclass, StudentMajor studentmajor) { super(); this.sno = sno; this.sname = sname; this.ssex = ssex; this.sclass = sclass; this.studentmajor = studentmajor; } public StudentMajor getStudentmajor() { return studentmajor; } public void setStudentmajor(StudentMajor studentmajor) { this.studentmajor = studentmajor; } public Integer getSno() { return sno; } public void setSno(Integer sno) { this.sno = sno; } public String getSname() { return sname; } public void setSname(String sname) { this.sname = sname; } public String getSsex() { return ssex; } public void setSsex(String ssex) { this.ssex = ssex; } @Override public String toString() { return "Student [sno=" + sno + ", sname=" + sname + ", ssex=" + ssex + ", sclass=" + sclass + ", studentmajor=" + studentmajor + "]"; } public Integer getSclass() { return sclass; } public void setSclass(Integer sclass) { this.sclass = sclass; } }