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

Graphical explanation of the underlying principle of JavaScript scope chain

Table of contents Preface Scope 1. What is scope?...

Designing the experience: What’s on the button

<br />Recently, UCDChina wrote a series of a...

Repair solution for inconsistent MySQL GTID master and slave

Table of contents Solution 1: Rebuild Replicas Pr...

mysql solves time zone related problems

Preface: When using MySQL, you may encounter time...

In-depth analysis of Nginx virtual host

Table of contents 1. Virtual Host 1.1 Virtual Hos...

Docker-compose installation yml file configuration method

Table of contents 1. Offline installation 2. Onli...

How to use Navicat to export and import mysql database

MySql is a data source we use frequently. It is v...

Vue commonly used high-order functions and comprehensive examples

1. Commonly used high-order functions of arrays S...

Introduction to the use of anchors (named anchors) in HTML web pages

The following information is compiled from the Int...

Use Javascript to develop sliding-nav navigation plug-in with sliding bar effect

Table of contents 1. Introduction 2. Usage 3. Dev...

Classification of web page color properties

Classification of color properties Any color can ...

Node.js solves the problem of Chinese garbled characters in client request data

Node.js solves the problem of Chinese garbled cha...

VMware Tools installation and configuration tutorial for Ubuntu 18.04

This article records the installation and configu...