1、在开发获取消息的需求中,需将消息正序排列,根据当前页面的最上一条记录的Id,获取上一页记录(即该id前的最新记录)
2、解决思路,因为该Id是按照时间自动升序排列,选择倒序筛选<id的pageSize条记录,再将其转化为顺序排列:
(1)sql语句为:
SELECT * FROM `messages` WHERE ((`mfrom` = 'abc' AND `mto`= 'bcd') \r\n"
+ "OR (`mfrom` = 'bcd' AND `mto`= 'abc')) AND `id` < ID AND `mtype` = 3 ORDER BY `id` DESC LIMIT 0, pageSize;
(选择按照时间排序也可以)
(2)将得到的list集合由倒序转为顺序排列:
List<MemberChatMessagesVO> voList = new ArrayList<MemberChatMessagesVO>();
for (int i = list.size() - 1; i >= 0; i--) {
Messages messages = list.get(i);
voList.add(messageContainerService.buildMemberChatMessagesVO(messages, member));
}