MyBatis 自定义IPage 查询

2023-12-14 19:02:21
Mapper.xml 部分
    <select id="findCustomerDistributionOrder"
            resultType="com.ruoyi.web_api.weixinOrder.entity.WeixinOrder">
        SELECT
        ai_weixin_order.*
        FROM ai_weixin_order
        LEFT JOIN ai_distributor_customers on ai_weixin_order.create_user_id = ai_distributor_customers.user_id
        WHERE
        ai_distributor_customers.distributor_user_id = #{wxOrder.userId}
        <if test="wxOrder.ctype != null and wxOrder.ctype != ''">
            AND ai_weixin_order.ctype = #{wxOrder.ctype}
        </if>
        <if test="wxOrder.platform != null and wxOrder.platform != ''">
            AND ai_distributor_customers.platform = #{wxOrder.platform}
        </if>
        <if test="wxOrder.status != null and wxOrder.status != ''">
            AND ai_weixin_order.status = #{wxOrder.status}
        </if>
        <if test="wxOrder.isdeal != null and wxOrder.isdeal != ''">
            AND ai_weixin_order.isdeal = #{wxOrder.isdeal}
        </if>
    </select>

Mpper.java,

使用分页需要添加第一个参数:

@Param("page") Page<FindWeiXinOrder> page

第二个参数是查询条件:

@Param("wxOrder") FindWeiXinOrder wxOrder
public interface WeixinOrderMapper extends BaseMapper<WeixinOrder> {


    public IPage<WeixinOrder> findCustomerDistributionOrder(@Param("page") Page<FindWeiXinOrder> page, @Param("wxOrder") FindWeiXinOrder wxOrder);

}

ServiceImpl.java

@Service
public class WeixinOrderServiceImpl extends ServiceImpl<WeixinOrderMapper, WeixinOrder> implements IWeixinOrderService {

    public IPage<WeixinOrder> findCustomerDistributionOrder(FindWeiXinOrder weixinOrder){
        Page<FindWeiXinOrder> page = new Page<>(weixinOrder.getPageNum(), weixinOrder.getPageSize());
        return getBaseMapper().findCustomerDistributionOrder(page,weixinOrder);
    };

}

文章来源:https://blog.csdn.net/TaLinBoy/article/details/135000429
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。