Home  >  Article  >  System Tutorial  >  How to use MyBatis ResultMap for deduplication?

How to use MyBatis ResultMap for deduplication?

WBOY
WBOYforward
2024-01-05 12:18:43529browse
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!

Statement:
This article is reproduced at:linuxprobe.com. If there is any infringement, please contact admin@php.cn delete