sql 查询返回实体类,实体类中装有一个集合

1.实体类中的字段,get/set 方案自己生成,这里就不写了,list里面装的是另一个实体对象

public class StudentBillBean {
private String studentId;
private String child_name;
private String school_pid;
private String school_no;
private String grade;
private String class_in;
private List<ParentBillBean> users;

2.然后在mapper里面对应的关联

<resultMap id="Studnetbill" type="实体类的路径" >
<result column="studentId" property="studentId"/>
<result column="child_name" property="child_name"/>
<result column="class_in" property="class_in"/>
<result column="grade" property="grade"/>
<result column="school_no" property="school_no"/>
<result column="school_pid" property="school_pid"/>
<collection property="users" ofType="List中实体类的路径">
<result column="user_name" property="user_name"/>
<result column="user_mobile" property="user_mobile"/>
<result column="user_relation" property="user_relation"/>
</collection>
</resultMap>
3.然后就可以写sql进行查询了




原文地址:https://www.cnblogs.com/bt2882/p/11075611.html