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

OpenSSL implements two-way authentication tutorial (with server and client code)

1. Background 1.1 Problems A recent product testi...

Detailed explanation of 7 SSH command usages in Linux that you don’t know

A system administrator may manage multiple server...

A brief discussion on the correct posture of Tomcat memory configuration

1. Background Although I have read many blogs or ...

js basic syntax and maven project configuration tutorial case

Table of contents 1. js statement Second, js arra...

Detailed steps to install Docker 1.8 on CentOS 7

Docker supports running on the following CentOS v...

A collection of possible problems when migrating sqlite3 to mysql

Brief description Suitable for readers: Mobile de...

WeChat applet custom bottom navigation bar component

This article example shares the specific implemen...

How to compile and install PHP and Nginx in Ubuntu environment

This article describes how to compile and install...

Linux file system operation implementation

This reading note mainly records the operations r...

Detailed tutorial on installing ElasticSearch 6.4.1 on CentOS7

1. Download the ElasticSearch 6.4.1 installation ...

Implementation of multi-port mapping of nginx reverse proxy

Code Explanation 1.1 http:www.baidu.test.com defa...

Jenkins packaging microservices to build Docker images and run them

Table of contents Environment Preparation start 1...

Specific use of exception filter Exceptionfilter in nestjs

Speaking of Nestjs exception filter, we have to m...

Web page HTML ordered list ol and unordered list ul

Lists for organizing data After learning so many ...

Solve the problem of the container showing Exited (0) after docker run

I made a Dockerfile for openresty on centos7 and ...