Solution to the paging error problem of MySQL one-to-many association query

Solution to the paging error problem of MySQL one-to-many association query

The query data in the xml price inquiry contains a list, so a collection is required

<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>

The general paging query encapsulated by such a query system is incorrect, so you need to add paging to your own SQL to solve it.

<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>
    )
    LEFT JOIN XXX yop ON yo.id = yop.order_id
    LEFT JOIN XXXX you ON yo.user_id = you.id
  </select>

When passing in parameters, calculation is required

(offset - 1) * limit, limit

Summarize

The above is the solution to the MySQL one-to-many association query paging error problem introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • MySQL million-level data paging query optimization solution
  • Optimizing the performance of paging query for MySQL with tens of millions of data
  • MySQL Oracle and SQL Server paging query example analysis
  • Detailed explanation of MySQL limit usage and performance analysis of paging query statements
  • Detailed explanation of Mysql Limit paging query optimization
  • Introduction to the differences between paging query statements in Oracle, MySQL and SqlServe
  • Detailed explanation of paging query methods in mysql, mssql and oracle
  • Comparison of two solutions for paging query in MySQL
  • Examples of paging queries for three databases: oracle, mysql, and SqlServer
  • Several implementation methods and advantages and disadvantages of SQL paging query in MySQL

<<:  How to use geoip to restrict regions in nginx

>>:  Implementation of communication between Vue and Flask

Recommend

Summary of some common configurations and techniques of Nginx

Preface This article lists several common, practi...

Podman boots up the container automatically and compares it with Docker

Table of contents 1. Introduction to podman 2. Ad...

Encapsulate a simplest ErrorBoundary component to handle react exceptions

Preface Starting from React 16, the concept of Er...

Example of downloading files with vue+django

Table of contents 1. Overview 2. Django Project 3...

Practice using Golang to play with Docker API

Table of contents Installing the SDK Managing loc...

Basic tutorial on controlling Turtlebot3 mobile robot with ROS

Chinese Tutorial https://www.ncnynl.com/category/...

More popular and creative dark background web design examples

Dark background style page design is very popular...

How to set up virtual directories and configure virtual paths in Tomcat 7.0

Tomcat7.0 sets virtual directory (1) Currently, o...

Detailed analysis of compiling and installing vsFTP 3.0.3

Vulnerability Details VSFTP is a set of FTP serve...

Multi-service image packaging operation of Dockerfile under supervisor

Writing a Dockerfile Configure yum source cd /tmp...

How to use wangEditor in vue and how to get focus by echoing data

Rich text editors are often used when doing backg...

Understand the principle of page replacement algorithm through code examples

Page replacement algorithm: The essence is to mak...

How to use the EXPLAIN command in SQL

In daily work, we sometimes run slow queries to r...