加入收藏 | 设为首页 | 会员中心 | 我要投稿 景德镇站长网 (https://www.0798zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

mysql一对多关联查询分页错误问题的解决方法

发布时间:2022-02-23 15:27:52 所属栏目:MySql教程 来源:互联网
导读:xml问价中查询数据中包含list,需要使用collection resultMap id=XX type=com.XXX.XXXX id column=o_id jdbcType=BIGINT property=id / result column=o_user_id jdbcType=BIGINT property=userId / .... collection property=orderProductList ofType=com
      xml问价中查询数据中包含list,需要使用collection
 
<resultMap id="XX" type="com.XXX.XXXX">
    <id column="o_id" jdbcType="BIGINT" property="id" />
    <result column="o_user_id" jdbcType="BIGINT" property="userId" />
    ....
    <collection property="orderProductList" ofType="com.XXXXXX.XXXXX">
      <id column="p_id" jdbcType="BIGINT" property="id" />
      <result column="p_order_id" jdbcType="BIGINT" property="orderId" />
      ....
    </collection>
  </resultMap>
这样的查询系统封装的通用分页查询是不对的,所以需要自己sql中加入分页解决
 
<select id="XXX" resultMap="OrderListMap">
    SELECT
    you.nick_name,
    yo.id o_id,
    yo.user_id o_user_id
    FROM
    (
    SELECT * FROM
    youpin_order
    WHERE
    1 = 1
    <if test="status != null">
      and `status` = #{status}
    </if>
    <if test="page != null and limit != null">
    LIMIT #{page},
    #{limit}
    </if>
    ) yo
    LEFT JOIN XXX yop ON yo.id = yop.order_id
    LEFT JOIN XXXX you ON yo.user_id = you.id
  </select>
传入参数的时候需要计算
 
(offset - 1) * limit, limit
总结
 
       以上所述是小编给大家介绍的mysql一对多关联查询分页错误问题的解决方法,希望对大家有所帮助。

(编辑:景德镇站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!