There are two levels of reply in total (reply to comments, reply to replies under comments)
Comments Table (TFW_Comments), reply content table (TFW_UserResponse) and comment reply relationship table (TFW_MsgRelation)
Note: Readers automatically ignore the service organization ID field of the comment table. This field is equivalent to which post this comment is in (below the article)
1. Query the comment table based on the article ID or post ID. Get the comment (service ID for this article). First level (comments)
To obtain the second level reply (commentsId), you need to query in the relationship table based on the comment ID and the reply type equals 1. The second level (reply under the comment)
Get the third level reply information in the relationship table based on the comment ID, reply type 2, and reply ID. The third level (reply in the reply under the comment) Note: The reply ID is its superior
@Override public MapfindComments(JSONObject jsonObject) { data.clear(); String userId = jsonObject.getString("userId"); String role = this.role(jsonObject); if (role.equals("-1")){ //没有权限 data.put("error","-1"); data.put("msg","当前用户没有权限"); return data; } List
Other codes can be ignored. The main statements are:
List> info = commentsDao.findComment(jsonObject.getString("fWJLID"),null);
The above picture gets the comments based on FWJLID. (This can be used as the ID of the post to get the comments under the post) Level 1 display
corresponds to the SQL statement (OPT is my user table)
select tc.content ,tc.commentsId,convert(varchar(19),tc.startTime,120) as startTime,tc.recipientId ,tc.operatorId,zo.NAME as operatorName,tc.atId,zo.HeadImgUrl as operatorHeadImgUrl from TFW_Comments tc left join zd_opt zo on zo.AID = tc.operatorId where tc.FWJLID = 5101
Query results:
List> userResponse = userResponseDao.findUserResponse(commentsId, null, "","",null);
The above picture gets the reply under the comment based on commentsid. (Get the reply based on the comment ID) Second-level display
Corresponding sql statement
select tur.userResponseId,tur.operatorId,tur.recipientId,convert(varchar(19),tur.startTime,120) as startTime,tur.userRepContent,tmr.atId as tmrAtId, tmr.msgRelationId ,tmr.responseType,tmr.replyId, zo.NAME as operatorName, zo1.NAME as recipientName, zo.HeadImgUrl as operatorHeadImgUrl, zo1.HeadImgUrl as recipientHeadImgUrl from TFW_MsgRelation tmr left join TFW_UserResponse tur on tur.userResponseId = tmr.userResponseId left join zd_opt zo on zo.AID = tur.operatorId left join zd_opt zo1 on zo1.AID = tur.recipientId where tmr.commentsId = 47
Query result
twoReply = userResponseDao.findUserResponse(msgRelationId, userResponseId,"1","",null); //二级回复数据
The above picture is to obtain the secondary reply based on the comment ID (msgRelationId) and reply ID (userResponseId). The reply ID is also the parent class. It is the ID of the reply. The third layer display
corresponds to sql
select tur.userResponseId,tur.operatorId,tur.recipientId,convert(varchar(19),tur.startTime,120) as startTime,tur.userRepContent,tmr.atId as tmrAtId, tmr.msgRelationId ,tmr.responseType,tmr.replyId, zo.NAME as operatorName, zo1.NAME as recipientName, zo.HeadImgUrl as operatorHeadImgUrl, zo1.HeadImgUrl as recipientHeadImgUrl from TFW_MsgRelation tmr left join TFW_UserResponse tur on tur.userResponseId = tmr.userResponseId left join zd_opt zo on zo.AID = tur.operatorId left join zd_opt zo1 on zo1.AID = tur.recipientId where tmr.commentsId = 136 and tmr.replyId = 155
query result
##return page display and return body displayThe above is the detailed content of How to implement comment and reply functions in java. For more information, please follow other related articles on the PHP Chinese website!