mybatis中返回对象中包含其他对象数据
实体类
public class JudgmentCaseDetailVo {
private Long id;
private String cpwsId;
private String caseNo;
private String laTime;
private String sortTime;
private String caseType;
private List<CasePartyDetail> casePartys;
}
xml写法
<!--方法参数及返回值-- >
<resultMap id="detailMap" type="com.xquant.xcrms.modules.judicialinformation.entity.vo.JudgmentCaseDetailVo">
<id property="id" column="id"/>
<result property="cpwsId" column="CPWS_ID"/>
<result property="caseNo" column="CASE_NO"/>
<result property="laTime" column="LA_TIME"/>
<result property="sortTime" column="SORT_TIME"/>
<result property="caseType" column="CASE_TYPE"/>
<collection property="casePartys" ofType="com.xquant.xcrms.modules.judicialinformation.entity.po.CasePartyDetail">
<id property="id" column="detail_id"/>
<result property="cpwsId" column="detail_cpws_id"/>
<result property="title" column="TITLE"/>
<result property="partyType" column="PARTY_TYPE"/>
</collection>
</resultMap>
<!--查询方法-- >
<select id="selectDetailById" resultMap="detailMap">
select jc.* ,cpd.* from JUDGMENT_CASENO_INFO jc left join CASE_PARTY_DETAIL cpd on jc.CPWS_ID = cpd.CPWS_ID
<where>
1 = 1
<if test="id != null and id != ''">
and jc.ID = #{id}
</if>
</where>
</select>
值得注意的点在表字段名是相同的时候,column 对应的要改为不同的别名,查询方法的resultMap中要与返回的map绑定的ID名一致