最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java評(píng)論、回復(fù)功能設(shè)計(jì)與實(shí)現(xiàn)方法

 更新時(shí)間:2022年06月20日 10:22:28   作者:PoemOfficer  
很多項(xiàng)目或者系統(tǒng)都有評(píng)論或者回復(fù)的需求,但評(píng)論回復(fù)的實(shí)現(xiàn)往往都比較復(fù)雜,也不好實(shí)現(xiàn),下面這篇文章主要給大家介紹了關(guān)于java評(píng)論、回復(fù)功能設(shè)計(jì)與實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下

最近實(shí)現(xiàn)了評(píng)論和回復(fù)、點(diǎn)贊、@的功能。在這里分享一下我的設(shè)計(jì)思路(先分享評(píng)論和回復(fù)功能)。希望各位讀者給出一些不一樣的建議后期改進(jìn)。

效果展示

總共是兩層回復(fù) (回復(fù)評(píng)論、回復(fù)評(píng)論下的回復(fù))

數(shù)據(jù)庫設(shè)計(jì)

評(píng)論表(TFW_Comments)和回復(fù)內(nèi)容表(TFW_UserResponse)以及評(píng)論回復(fù)關(guān)系表(TFW_MsgRelation)

數(shù)據(jù)庫設(shè)計(jì)思路:

注:各位讀者自動(dòng)忽略評(píng)論表的服務(wù)機(jī)構(gòu)ID字段,這個(gè)字段相當(dāng)于這條評(píng)論是在哪個(gè)帖子(文章下面)

1、根據(jù)文章ID或者是帖子ID查詢?cè)u(píng)論表獲取評(píng)論(本文的服務(wù)機(jī)構(gòu)ID)。第一層(評(píng)論)

2、根據(jù)評(píng)論ID并且回復(fù)類型等于1的去關(guān)系表獲取第二層的回復(fù)(commentsId)。第二層(評(píng)論下的回復(fù))

3、根據(jù)評(píng)論ID、回復(fù)類型等于2、回復(fù)ID去關(guān)系表獲取第三層回復(fù)。第三層(評(píng)論下回復(fù)中的回復(fù))注:回復(fù)ID是它的上級(jí)

實(shí)現(xiàn)類源碼

@Override
    public Map<String, Object> findComments(JSONObject jsonObject) {
        data.clear();
        String userId = jsonObject.getString("userId");
 
        String role = this.role(jsonObject);
        if (role.equals("-1")){
            //沒有權(quán)限
            data.put("error","-1");
            data.put("msg","當(dāng)前用戶沒有權(quán)限");
            return data;
        }
 
        List<Map<String, Object>> info = commentsDao.findComment(jsonObject.getString("fWJLID"),null);
        //查詢點(diǎn)贊次數(shù)
        int countTag = 0;
        MsgRelationTag msgRelationTag = new MsgRelationTag();
 
        for (Map item : info){
            item.put("inputShow",false);
            int commentsId = (int) item.get("commentsId");
            //查詢點(diǎn)贊次數(shù)
             countTag = msgRelationDao.findCountTagByTagId(commentsId,1);
            item.put("countTag",countTag);
            //設(shè)置點(diǎn)贊狀態(tài)
            msgRelationTag.setTagId(commentsId);
            msgRelationTag.setTagType(1);
            msgRelationTag.setTagUserId(Integer.parseInt(userId));
            MsgRelationTag msgTag = msgRelationDao.findMsgTag(msgRelationTag);
            if (msgTag != null) {
                item.put("tagStatus",msgTag.getStatus());
            }else {
                item.put("tagStatus","");
            }
            //如果有@id
            if (item.get("atId") != null){
                String content = item.get("content").toString();
                StringBuffer tmrAtId = findUserName(item.get("atId").toString());
                item.put("content",content+'@'+tmrAtId);
            }
            //二級(jí)回復(fù)數(shù)據(jù)
            List<Map<String, Object>> twoReply = new ArrayList<>();
            //所有數(shù)據(jù)
            List<Map<String, Object>> userResponse = userResponseDao.findUserResponse(commentsId, null, "","",null);
            for (Map userResponseInfo :userResponse){
                int userResponseIds = Integer.parseInt(userResponseInfo.get("userResponseId").toString());
                //查詢點(diǎn)贊次數(shù)
                countTag = msgRelationDao.findCountTagByTagId(userResponseIds,2);
                //設(shè)置點(diǎn)贊狀態(tài)
                msgRelationTag.setTagId(userResponseIds);
                msgRelationTag.setTagType(2);
                msgTag = msgRelationDao.findMsgTag(msgRelationTag);
                if (msgTag != null) {userResponseInfo.put("tagStatus",msgTag.getStatus());}else {userResponseInfo.put("tagStatus","");}
                userResponseInfo.put("countTag",countTag);
                userResponseInfo.put("inputShow",false);
                Integer responseType = (Integer) userResponseInfo.get("responseType");
                for (Map stairReplyInfo : userResponse){
                    Integer  userResponseId = (Integer) stairReplyInfo.get("userResponseId");
                    int msgRelationId = Integer.parseInt(stairReplyInfo.get("msgRelationId").toString());
                    //接受者id*/
                    twoReply = userResponseDao.findUserResponse(msgRelationId, userResponseId,"1","",null); //二級(jí)回復(fù)數(shù)據(jù)
                    for (Map twoReplyItem : twoReply){
                        int twoReplyId = Integer.parseInt(twoReplyItem.get("userResponseId").toString());
                        twoReplyItem.put("inputShow",false);
                        //查詢點(diǎn)贊次數(shù)
                        countTag = msgRelationDao.findCountTagByTagId(twoReplyId,2);
                        twoReplyItem.put("countTag",countTag);
                        //設(shè)置點(diǎn)贊狀態(tài)
                        msgRelationTag.setTagId(twoReplyId);
                        msgTag = msgRelationDao.findMsgTag(msgRelationTag);
                        if (msgTag != null) {twoReplyItem.put("tagStatus",msgTag.getStatus());}else {twoReplyItem.put("tagStatus","");}
                        String userRepContent = twoReplyItem.get("userRepContent").toString();
                        if (twoReplyItem.get("tmrAtId") != null){
                            StringBuffer tmrAtId = findUserName(twoReplyItem.get("tmrAtId").toString());
                            twoReplyItem.put("userRepContent",userRepContent+'@'+tmrAtId);
                        }
 
                    }
                    stairReplyInfo.put("twoReply",twoReply);
                }
            }
            item.put("stairReply",userResponse);
        }
        data.put("data",info);
        data.put("error",0);
        data.put("msg","查詢成功");
        return data;
    }

其它的代碼可以忽略。主要語句有:

獲取帖子下的評(píng)論

 List<Map<String, Object>> info = commentsDao.findComment(jsonObject.getString("fWJLID"),null);

上圖根據(jù)FWJLID獲取評(píng)論。(此處可以當(dāng)成帖子的ID,獲取帖子下的評(píng)論)一級(jí)展示

對(duì)應(yīng)SQL語句(OPT是我的用戶表)

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

查詢結(jié)果:

 獲取評(píng)論下的回復(fù)

List<Map<String, Object>> userResponse = userResponseDao.findUserResponse(commentsId, null, "","",null);

上圖根據(jù)commentsid獲取評(píng)論下的回復(fù)。(根據(jù)評(píng)論ID獲取回復(fù))二級(jí)展示

對(duì)應(yīng)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 = 47

查詢結(jié)果

 獲取二級(jí)回復(fù)

 twoReply = userResponseDao.findUserResponse(msgRelationId, userResponseId,"1","",null); //二級(jí)回復(fù)數(shù)據(jù)

上圖是根據(jù)評(píng)論ID(msgRelationId)和回復(fù)ID(userResponseId)去獲取二級(jí)回復(fù)?;貜?fù)ID也就是父類。就是回復(fù)那一條回復(fù)的ID。 第三層展示

對(duì)應(yīng)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

查詢結(jié)果

返回頁面展示和返回體展示

總結(jié)

到此這篇關(guān)于java評(píng)論、回復(fù)功能設(shè)計(jì)與實(shí)現(xiàn)方法的文章就介紹到這了,更多相關(guān)java評(píng)論回復(fù)功能內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 淺析Java自定義注解的用法

    淺析Java自定義注解的用法

    注解為我們?cè)诖a中添加信息提供一種形式化的方法,使我們可以在源碼、編譯時(shí)、運(yùn)行時(shí)非常方便的使用這些數(shù)據(jù)。本文主要為大家介紹了Java自定義注解的用法,希望對(duì)大家有所幫助
    2023-03-03
  • Java實(shí)現(xiàn)圖片合成的示例詳解

    Java實(shí)現(xiàn)圖片合成的示例詳解

    前端有一個(gè)神器——canvas,這個(gè)畫布標(biāo)簽可以處理各種圖片的合成,可以精確到圖片的具體坐標(biāo)。java后端也有這樣的神器,那就是image-combiner,可以很簡(jiǎn)單的合成圖片,感興趣的可以試一試
    2022-01-01
  • java優(yōu)先隊(duì)列PriorityQueue中Comparator的用法詳解

    java優(yōu)先隊(duì)列PriorityQueue中Comparator的用法詳解

    這篇文章主要介紹了java優(yōu)先隊(duì)列PriorityQueue中Comparator的用法詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-02-02
  • springboot使用redis的詳細(xì)步驟

    springboot使用redis的詳細(xì)步驟

    SpringBoot對(duì)常用的數(shù)據(jù)庫支持外,對(duì)NoSQL?數(shù)據(jù)庫也進(jìn)行了封裝自動(dòng)化,下面這篇文章主要給大家介紹了關(guān)于springboot使用redis的詳細(xì)步驟,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-06-06
  • java反射機(jī)制示例

    java反射機(jī)制示例

    這篇文章主要介紹了java反射機(jī)制示例,需要的朋友可以參考下
    2014-04-04
  • 解決MultipartFile.transferTo(dest) 報(bào)FileNotFoundExcep的問題

    解決MultipartFile.transferTo(dest) 報(bào)FileNotFoundExcep的問題

    這篇文章主要介紹了解決MultipartFile.transferTo(dest) 報(bào)FileNotFoundExcep的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • Java BIO,NIO,AIO總結(jié)

    Java BIO,NIO,AIO總結(jié)

    這篇文章主要介紹了Java BIO,NIO,AIO的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)Java,感興趣的朋友可以了解下
    2020-09-09
  • Java整型數(shù)與網(wǎng)絡(luò)字節(jié)序byte[]數(shù)組轉(zhuǎn)換關(guān)系詳解

    Java整型數(shù)與網(wǎng)絡(luò)字節(jié)序byte[]數(shù)組轉(zhuǎn)換關(guān)系詳解

    這篇文章主要介紹了Java整型數(shù)與網(wǎng)絡(luò)字節(jié)序byte[]數(shù)組轉(zhuǎn)換關(guān)系,結(jié)合實(shí)例形式歸納整理了java整型數(shù)和網(wǎng)絡(luò)字節(jié)序的byte[]之間轉(zhuǎn)換的各種情況,需要的朋友可以參考下
    2017-08-08
  • Java使用Canal同步MySQL數(shù)據(jù)到Redis

    Java使用Canal同步MySQL數(shù)據(jù)到Redis

    在現(xiàn)代微服務(wù)架構(gòu)中,數(shù)據(jù)同步是一個(gè)常見的需求,特別是將?MySQL?數(shù)據(jù)實(shí)時(shí)同步到?Redis,下面我們就來看看Java如何使用Canal同步MySQL數(shù)據(jù)到Redis吧
    2024-11-11
  • spring簡(jiǎn)單MVC實(shí)現(xiàn)方法(URL映射及其參數(shù)使用、查詢(id、其他參數(shù))、增加)

    spring簡(jiǎn)單MVC實(shí)現(xiàn)方法(URL映射及其參數(shù)使用、查詢(id、其他參數(shù))、增加)

    這篇文章主要介紹了spring簡(jiǎn)單MVC實(shí)現(xiàn)方法(URL映射及其參數(shù)使用、查詢(id、其他參數(shù))、增加),方法參數(shù)使用包括在無注解下獲取參數(shù),使用@RequestParam 獲取參數(shù)的方法,每種方法講解的非常詳細(xì),需要的朋友可以參考下
    2024-01-01

最新評(píng)論

宜黄县| 奈曼旗| 唐河县| 长汀县| 江油市| 临漳县| 平阴县| 平昌县| 黄平县| 通渭县| 陇西县| 泽州县| 北安市| 辽宁省| 泰州市| 吴桥县| 沙河市| 武功县| 夏河县| 芷江| 宣武区| 西乌珠穆沁旗| 枞阳县| 衡水市| 大荔县| 桑植县| 淮滨县| 乌拉特后旗| 保德县| 泸水县| 宁波市| 东光县| 德保县| 三河市| 揭西县| 沁源县| 大关县| 武城县| 班戈县| 杭锦旗| 定南县|