发送私信功能开发;
功能开发
数据访问层
message-mapper.xml 增加
<insert id="insertMessage" parameterType="Message" keyProperty="id"> insert into message(<include refid="insertFields"></include>) values(#{fromId},#{toId},#{conversationId},#{content},#{status},#{createTime}) </insert> <update id="updateStatus"> update message set status = #{status} where id in <foreach collection="ids" item="id" open="(" separator="," close=")"> #{id} </foreach> </update>
MessageMapper 增加:
// 新增消息 int insertMessage(Message message); // 修改消息的状态 int updateStatus(List<Integer> ids, int status);
业务层开发:
public int addMessage(Message message) { message.setContent(HtmlUtils.htmlEscape(message.getContent())); message.setContent(sensitiveFilter.filter(message.getContent())); return messageMapper.insertMessage(message); } public int readMessage(List<Integer> ids) { return messageMapper.updateStatus(ids, 1); }
表现层:
public int addMessage(Message message) { message.setContent(HtmlUtils.htmlEscape(message.getContent())); message.setContent(sensitiveFilter.filter(message.getContent())); return messageMapper.insertMessage(message); } public int readMessage(List<Integer> ids) { return messageMapper.updateStatus(ids, 1); }
接下来就是页面处理。