实现排序取前几条数据
@Override
public List<Notice> selectNewlyNotice() {NoticeExample noticeExample = new NoticeExample();noticeExample.setOrderByClause("noti_id desc");List<Notice> notices = noticeMapper.selectByExample(noticeExample).stream().limit(5).collect(Collectors.toList());return notices;
}
说明:首先使用example进行排序,然后按照这个example的条件放到select中进行查询,查询完后使用stream流函数进行处理,limit(x) x表示截取的几条数据。然后collect()函数是将流转为list集合。