Home > System Tutorial > LINUX > body text

How to use MyBatis ResultMap for deduplication?

WBOY
Release: 2024-01-05 12:18:43
forward
563 people have browsed it
Introduction Sometimes MyBatis is used to query the result set and the printed sql statement is executed on the database client. For example, the result is 10, but MyBatis returns only 4 data. Why is this?

The ResultMap of MyBatis uses id as the primary key of the map by default. When the id is the same, it is regarded as the same record regardless of whether other fields are different. So when we want MyBatis not to remove duplicates, how do we do it? Just add a pseudo id as an identifier in the POJO definition. like:

Add a "pseudo column" in the main table class (User.java), the function is: not to remove duplicates

MyBatis ResultMap去重操作,怎样操作

UserMapper.xml

MyBatis ResultMap去重操作,怎样操作

operation result

MyBatis ResultMap去重操作,怎样操作Principle: This sql statement generates a column of non-duplicate data, such as row number; using this column as the primary key, MyBatis detects that the primary key is non-duplicate, so multiple data records are returned.

The above is the detailed content of How to use MyBatis ResultMap for deduplication?. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!