树形列表显示主表信息和明细信息,后台数据获取:使用集合的嵌套 Select 查询

时光毁灭记忆、已成空白 提交于 2020-03-17 22:17:20

某厂面试归来,发现自己落伍了!>>>

树形列表显示主表信息和明细信息,后台数据获取:

方法一:

@Override
public IPage<FeeReceivingVO> getPageList(IPage<FeeReceivingVO> page, String condition,Integer feeType,Integer acountsType) {
    IPage<FeeReceivingVO> list= baseMapper.getPageList(page ,condition, feeType, acountsType);
    for (FeeReceivingVO item : list.getRecords()) {
        List<FeeReceivingDetailVO> children = FeeReceivingDetailMapper.geDetailByReceivingId(item.getId());
        if(children!=null) {
            item.setChildren(children);
        }
    }
    return list;
}

方法二:这样查询结果条数为明细结果条数

方法三:

<!--组合主表和明细表-->
<resultMap id="feeReceivingResult" type="com.canyou.fee.entity.FeeReceivingVO">
    <result column="id" property="id" />
    <collection property="children" javaType="ArrayList" column="id" ofType="com.canyou.fee.entity.FeeReceivingDetailVO" select="geDetailByReceivingId"/>
</resultMap>
<!--根据条件获取主表信息(需在mapper申明)-->
<select id="getPageList" resultMap="feeReceivingResult">
  SELECT * FROM fee_fee_receiving
</select>
<!--根据主表id获取应收明细(需在mapper申明)-->
<select id="geDetailByReceivingId" resultType="com.canyou.fee.entity.FeeReceivingDetailVO">
  SELECT *
    FROM
    fee_fee_receiving_detail AS fd
    WHERE  fd.is_deleted = 0 AND  fd.receiving_id = #{id}
</select>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!