30 lines
1.3 KiB
XML
30 lines
1.3 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
|
<mapper namespace="com.xubx.springboot_01demo.mapper.MessagesMapper">
|
|
<!--1.发送消息-->
|
|
<insert id="sendMessages" parameterType="com.xubx.springboot_01demo.entity.pojo.Messages">
|
|
insert into messages (sender, recipient, content, state, created)
|
|
values (#{sender}, #{recipient}, #{content}, #{state}, #{created})
|
|
</insert>
|
|
<!--2.获取历史记录-->
|
|
<select id="getMessages" resultType="com.xubx.springboot_01demo.entity.vo.historyMessagesVo">
|
|
SELECT ch.sender,
|
|
ch.recipient,
|
|
ch.content,
|
|
ch.state,
|
|
ch.created,
|
|
register.avatar AS avatar
|
|
FROM messages ch
|
|
JOIN register on ch.sender = register.username
|
|
WHERE (ch.sender = #{sender} AND ch.recipient = #{recipient})
|
|
OR (ch.sender = #{recipient} AND ch.recipient = #{sender})
|
|
ORDER BY ch.created;
|
|
</select>
|
|
<!--3.将state设置为已读-->
|
|
<update id="updateState" parameterType="com.xubx.springboot_01demo.entity.pojo.Messages">
|
|
update messages
|
|
set state = #{state}
|
|
where sender = #{recipient} and recipient = #{sender} and state = 0;
|
|
</update>
|
|
</mapper> |