MyBatis-Plus使用collection一对多查询导致分页信息错误

需要修改collection写法,将collection由一次查询,改为两次查询

例:一位用户有多个地块,一个地块由多个坐标点(经纬度)组成,查询当前用户下的所有土地信息及坐标点

Entity:

FarmerPlotDTO.java

@ApiModelProperty(value = "地块id")
private Long id;

@ApiModelProperty(value = "面积")
private BigDecimal area;

@ApiModelProperty(value = "周长")
private BigDecimal perimeter;

@ApiModelProperty(value = "坐标点")
private List<FarmerPlotPointDTO> positions;
FarmerPlotPointDTO.java

@ApiModelProperty(value = "经度")
private BigDecimal longitude;

@ApiModelProperty(value = "纬度")
private BigDecimal latitude;

修改前一次查询:

<resultMap id="FarmerPlotMap" type="FarmerPlotDTO">
    <id column="id" property="id" />
    <result column="area" property="area" />
    <result column="perimeter" property="perimeter" />
    <collection property="positions" ofType="FarmerPlotPointDTO">
        <result column="latitude" property="latitude"/>
        <result column="longitude" property="longitude"/>
    </collection>
</resultMap>

修改后两次查询:

collection增加select和column属性

说明:column中的值来自第一次查询,作为第二次查询的入参

<resultMap id="FarmerPlotMap" FarmerPlotDTO">
    <id column="id" property="id" />
    <result column="area" property="area" />
    <result column="perimeter" property="perimeter" />
    <collection property="positions" ofType="FarmerPlotPointDTO"
                select="getPointById" column="id">
        <result column="latitude" property="latitude"/>
        <result column="longitude" property="longitude"/>
    </collection>
</resultMap>
<select id="getPointById" resultType="FarmerPlotPointDTO">
    SELECT longitude, latitude FROM farmer_plot_point WHERE plot_id = #{id}
</select>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值