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 UserMapper.xml operation resultPrinciple: 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!