mybatis中多表查询collection封装后分页问题解决

飞一样的编程
飞一样的编程
擅长邻域:Java,MySQL,Linux,nginx,springboot,mongodb,微信小程序,vue

分类: ssm 专栏: ssm框架课 标签: mybatis分页

2024-10-09 16:25:47 149浏览

mybatis分页

分页查询所有订单(订单基本信息表  订单详情表  商品表  一起查)

 //查询所有的订单  偏移量   (当前页-1)*pageSize

    List<BaseOrder> selectList(@Param("userId") Integer userId, @Param("offset")Integer offset, @Param("pageSize") Integer pageSize);

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.interestingshop.mapper.BaseOrderMapper">


    <resultMap id="orderInfoWithGoods" type="orderInfo">
        <id column="id" property="id"></id>
        <result column="amount" property="amount"/>
        <result column="buyNum" property="buyNum"/>
        <result column="id" property="baseOrderId"/>
        <result column="goodsId" property="goodsId"/>
        <association property="goods" javaType="goods" >
            <id column="gid" property="id"></id>
            <result column="goodsName" property="goodsName"/>
            <result column="fileName" property="fileName"/>
            <result column="price" property="price"/>
        </association>


    </resultMap>


    <select id="withOrderInfo" resultMap="orderInfoWithGoods">
        select
            i.*, g.*, g.id as gid
        from
            t_order_info i
        left join
            t_goods g on g.id = i.goodsId
        where
            i.baseOrderId = #{id}
    </select>

    <resultMap id="BaseOrderWithOrderInfoWithGoods" type="baseOrder">

        <id column="id" property="id"></id>

        <result column="account" property="account"/>
        <result column="orderNo" property="orderNo"/>
        <result column="userAddress" property="userAddress"/>
        <result column="amount" property="amount"/>

        <collection property="orderInfoList" ofType="orderinfo" select="withOrderInfo"  column="id">



        </collection>

    </resultMap>



    
    <select id="selectList" resultMap="BaseOrderWithOrderInfoWithGoods">
        SELECT
            b.*
        FROM
            t_base_order b
        <where>
            <if test="userId != null">
                b.userId = #{userId}
            </if>
        </where>

        limit #{offset},#{pageSize}

    </select>

</mapper>

好博客就要一起分享哦!分享海报

此处可发布评论

评论(0展开评论

暂无评论,快来写一下吧

展开评论

您可能感兴趣的博客

客服QQ 1913284695