主对象
@Data
public class AllocationInfo2 {
@ApiModelProperty(value = "项目编号")
private String projectId;
@ApiModelProperty(value = "项目类别")
private String category;
@ApiModelProperty(value = "项目负责人")
private String leader;
@ApiModelProperty(value = "项目说明")
private String instruction;
@ApiModelProperty(value = "项目分配的成员信息")
private List<Teacher> teachers;
}
子对象
@Data
public class Teacher {
/**
* 用户名
*/
private String username;
/**
* 用户ID
*/
private String userId;
@Override
public String toString() {
return "教师名称:"+username+" 教师工号"+userId+"\n";
}
}
xml中的resultMap(核心)
注意子对象的前缀, columnPrefix="t_"
<resultMap id="Allocation" type="group.uchain.project_management_system.vo.AllocationInfo2">
<id column="id" property="projectId"/>
<result column="category" property="category"/>
<result column="leader" property="leader"/>
<result column="instruction" property="instruction"/>
<collection property="teachers" ofType="group.uchain.project_management_system.vo.Teacher"
javaType="java.util.ArrayList" columnPrefix="t_">
<id column="user_id" property="userId" jdbcType="BIGINT"/>
<id column="username" property="username" jdbcType="VARCHAR"/>
</collection>
</resultMap>
xml中的SQL
<select id="getAllAllocationInfo" resultMap="Allocation" resultType="group.uchain.project_management_system.vo.AllocationInfo2">
select p.id,p.category,p.leader,p.instruction,a.user_id as t_user_id,u.username as t_username
from project_info p,allocation_info a
inner join user u
on a.user_id = u.user_id
where p.id = a.project_id
</select>
测试结果
2019-08-18 11:50:05.824 INFO 32141 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited
[AllocationInfo2(projectId=V28, category=专业认证, leader=王五, instruction=计算机公共基础协助2018年石工和化工的专业认证, teachers=[教师名称:小明 教师工号123456789101
, 教师名称:李四 教师工号123456789102
])]
网友评论