站内信的实现

• 站内信的实现

 
• 站内信
“站内信”主要实现站内用户的沟通,有两个基本功能。
一:点到点的消息传送。用户给用户发送站内信,管理员给用户发送站内信。
二:点到面的消息传送。管理员给用户(指定满足某一条件的用户群)群发消息
站内信的开发流程
1. Database Column
2. Model:模型定义,和数据库相匹配
3. DAO:数据读取
4. Service:服务包装
5. Controller:业务入口
6. Test
 
1. Database Column
private int id ;
private int from_Id ;
private int to_Id ;
private String content ;
private Date createdDate ;
private int hasRead ;
2. Model:模型定义,和数据库相匹配
package com.LG.model ;
import java.util.Date ;
 
/**
* @Author liguo
* @Description
* @Data 2018-09-06 14:21
*/
 
public class Message {
private int id ;
private int fromId ;
private int toId ;
private String content ;
private Date createdDate ;
private int hasRead ;
 
public int getId () {
return id ;
}
 
public void setId ( int id ) {
this . id = id ;
}
 
public int getFromId () {
return fromId ;
}
 
public void setFromId ( int fromId ) {
this . fromId = fromId ;
}
 
public int getToId () {
return toId ;
}
 
public void setToId ( int toId ) {
this . toId = toId ;
}
 
public String getContent () {
return content ;
}
 
public void setContent ( String content ) {
this . content = content ;
}
 
public Date getCreatedDate () {
return createdDate ;
}
 
public void setCreatedDate ( Date createdDate ) {
this . createdDate = createdDate ;
}
 
public int getHasRead () {
return hasRead ;
}
 
public void setHasRead ( int hasRead ) {
this . hasRead = hasRead ;
}
 
public String getConversationId () {
if ( fromId < toId ) {
return String . format ( "%d_%d" , fromId , toId ) ;
} else {
return String . format ( "%d_%d" , toId , fromId ) ;
}
}
 
public void setConversationId ( String conversationId ) {
String conversationId1 = conversationId ;
}
}
3. DAO:数据读取
package com.LG.dao ;
 
import com.LG.model.Message ;
import org.apache.ibatis.annotations. Insert ;
import org.apache.ibatis.annotations. Mapper ;
import org.apache.ibatis.annotations. Param ;
import org.apache.ibatis.annotations. Select ;
 
import java.util. List ;
 
/**
* @Author liguo
* @Description
* @Data 2018-09-06 14:38
*/
 
 
@Mapper
public interface MessageDAO {
String TABLE_NAME = " message " ;
String INSERT_FIELDS = " from_id, to_id, content, has_read, conversation_id, created_date " ;
String SELECT_FIELDS = " id, " + INSERT_FIELDS ;
 
@Insert ( { "insert into " , TABLE_NAME , "(" , INSERT_FIELDS ,
") values (#{fromId},#{toId},#{content},#{hasRead},#{conversationId},#{createdDate})" } )
int addMessage ( Message message ) ;
 
@Select ( { "select " , SELECT_FIELDS , " from " , TABLE_NAME ,
" where conversation_id=#{conversationId} order by created_date desc limit #{offset}, #{limit}" } )
List < Message > getConversationDetail ( @Param ( "conversationId" ) String conversationId ,
@Param ( "offset" ) int offset ,
@Param ( "limit" ) int limit ) ;
 
@Select ( { "select " , INSERT_FIELDS , " , count(id) as id from ( select * from " , TABLE_NAME ,
" where from_id=#{userId} or to_id=#{userId} order by created_date desc) tt group by conversation_id order by created_date desc limit #{offset}, #{limit}" } )
//实现分页功能;offset是分的页数目 ,limit为每页显示的内容;
List < Message > getConversationList ( @Param ( "userId" ) int userId ,
@Param ( "offset" ) int offset ,
@Param ( "limit" ) int limit ) ;
 
@Select ( { "select count(id) from " , TABLE_NAME , " where has_read=0 and to_id=#{userId} and conversation_id=#{conversationId}" } )
int getConversationUnreadCount ( @Param ( "userId" ) int userId , @Param ( "conversationId" ) String conversationId ) ;
}
4. Service:服务包装
 
5. Controller:业务入口
6. Test
 

转载于:https://www.cnblogs.com/liguo-wang/p/9600277.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值