夜雨声烦 | 7e6eb38 | 2025-04-22 01:18:00 +0800 | [diff] [blame] | 1 | package com.example.g8backend.mapper; |
| 2 | |
| 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| 4 | import com.example.g8backend.entity.Message; |
| 5 | import org.apache.ibatis.annotations.Mapper; |
| 6 | import org.apache.ibatis.annotations.Param; |
| 7 | import org.apache.ibatis.annotations.Select; |
| 8 | |
| 9 | import java.util.List; |
| 10 | |
| 11 | @Mapper |
| 12 | public interface MessageMapper extends BaseMapper<Message> { |
| 13 | @Select("SELECT * FROM private_messages " + |
| 14 | "WHERE (sender_id=#{userId1} AND receiver_id=#{userId2}) " + |
| 15 | "OR (sender_id=#{userId2} AND receiver_id=#{userId1}) " + |
| 16 | "ORDER BY sent_at") |
| 17 | List<Message> selectConversation(@Param("userId1") Long userId1, @Param("userId2") Long userId2); |
| 18 | |
| 19 | @Select("SELECT * FROM private_messages " + |
| 20 | "WHERE sender_id=#{userId} OR receiver_id=#{userId} " + |
| 21 | "ORDER BY sent_at DESC") |
| 22 | List<Message> selectUserMessages(Long userId); |
| 23 | } |