一个class中有许多student,属于一对多关系。本文利用mybatis注解,嵌套查询方式来实现一对多查询,在根据classId查询class时,顺便查询并展示出class中的student
student实体类
package com.itheima.dao;
public class StudentDao {
private Integer id;
private String name;
private Integer age;
private Integer cid;
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 Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Integer getCid() {
return cid;
}
public void setCid(Integer cid) {
this.cid = cid;
}
@Override
public String toString() {
return "StudentDao{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
", cid=" + cid +
'}';
}
}
class实体类
package com.itheima.dao;
import java.util.List;
public class ClassDao {
private Integer id;
private String className;
private List<StudentDao> studentsList;
public Integer getId() {
return id;
}
public void setId(