实现站内信和评论服务

Posted liguo-wang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实现站内信和评论服务相关的知识,希望对你有一定的参考价值。

• 评论中心

• 站内信
 
 
• 评论中心
需要评论的各种场景服务:
评论中心的设计:统一的评论服务,覆盖所有的实体,可以进行评论
通用的模块开发流程
1. Database Column
2. Model:模型定义,和数据库相匹配
3. DAO:数据读取
4. Service:服务包装
5. Controller:业务入口
6. Test
站内信开发流程
1. Database Column
id
content
entity_id ->questionId/commentId //表示任意实体的id;
entity_type question/comment //表示评论的对象
created_date
user_id
2. Model:模型定义,和数据库相匹配
package com.nowcoder.model;
 
import java.util.Date;
 
/**
* @Author liguo
* @Description
* @Data 2018-09-06 7:50
*/
public class Comment {
private int id;
private int userId;
private int entityId;
private int entityType;
private String content;
private Date createdDate;
private int status;
 
public int getId() {
return id;
}
 
public void setId(int id) {
this.id = id;
}
 
public int getUserId() {
return userId;
}
 
public void setUserId(int userId) {
this.userId = userId;
}
 
public int getEntityId() {
return entityId;
}
 
public void setEntityId(int entityId) {
this.entityId = entityId;
}
 
public int getEntityType() {
return entityType;
}
 
public void setEntityType(int entityType) {
this.entityType = entityType;
}
 
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 getStatus() {
return status;
}
 
public void setStatus(int status) {
this.status = status;
}
}
 
3. DAO:数据读取
 
//数据库接口的crud
@Mapper
public interface CommentDAO {
String TABLE_NAME = " comment ";
String INSERT_FIELDS = " user_id, content, created_date, entity_id, entity_type, status ";
String SELECT_FIELDS = " id, " + INSERT_FIELDS;
 
@Insert({"insert into ", TABLE_NAME, "(", INSERT_FIELDS,
") values (#{userId},#{content},#{createdDate},#{entityId},#{entityType},#{status})"})
int addComment(Comment comment);
 
@Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME, " where id=#{id}"})
Comment getCommentById(int id);
 
@Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME,
" where entity_id=#{entityId} and entity_type=#{entityType} order by created_date desc"})
List<Comment> selectCommentByEntity(@Param("entityId") int entityId, @Param("entityType") int entityType);
 
@Select({"select count(id) from ", TABLE_NAME, " where entity_id=#{entityId} and entity_type=#{entityType}"})
int getCommentCount(@Param("entityId") int entityId, @Param("entityType") int entityType);
 
@Update({"update comment set status=#{status} where id=#{id}"})
int updateStatus(@Param("id") int id, @Param("status") int status);
 
@Select({"select count(id) from ", TABLE_NAME, " where user_id=#{userId}"})
int getUserCommentCount(int userId);
 
4. Service:服务包装
 
5. Controller:业务入口
6. Test
• 站内信
 
 
 

以上是关于实现站内信和评论服务的主要内容,如果未能解决你的问题,请参考以下文章

AI柠檬网站上线站内搜索引擎,支持语音搜索

微信和支付宝支付模式详解及实现二

8_1_异步设计和站内邮件通知系统

微信和支付宝实现

简易的站内搜索引擎 (万字长文!!绝对值得一看!!)

简易的站内搜索引擎 (万字长文!!绝对值得一看!!)