码迷,mamicode.com
首页 > 其他好文 > 详细

实现站内信和评论服务

时间:2018-09-06 14:44:37      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:ddc   radius   ola   add   数据库   from   数据读取   values   order by   

• 评论中心

• 站内信
 
 
• 评论中心
需要评论的各种场景服务:
评论中心的设计:统一的评论服务,覆盖所有的实体,可以进行评论
通用的模块开发流程
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
• 站内信
 
 
 

实现站内信和评论服务

标签:ddc   radius   ola   add   数据库   from   数据读取   values   order by   

原文地址:https://www.cnblogs.com/liguo-wang/p/9597750.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!