有几种方法可以处理MyBatis结果集中的重复数据:
SELECT DISTINCT * FROM table_name;
<resultMap id="exampleResultMap" type="example">
<id property="id" column="id" />
<result property="name" column="name" />
<collection property="list" ofType="item" column="item_id" distinct="true"/>
</resultMap>
List<Example> resultList = sqlSession.selectList("selectExample");
List<Example> uniqueList = new ArrayList<>();
Set<String> seen = new HashSet<>();
for (Example example : resultList) {
if (seen.add(example.getId())) {
uniqueList.add(example);
}
}
这些方法可以根据具体情况选择合适的方式来处理MyBatis结果集中的重复数据。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:如何处理oracle multiset中的重复数据