1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        springboot+vue前后分離實(shí)現(xiàn)仿qq空間評(píng)論功能

        共 9468字,需瀏覽 19分鐘

         ·

        2021-01-13 04:40


        案例功能效果圖

        前端評(píng)論列表頁面效果圖

        環(huán)境介紹

        前端:vue

        后端:springboot

        jdk:1.8及以上

        數(shù)據(jù)庫:mysql


        完整源碼獲取方式



        源碼獲取方式

        掃碼關(guān)注回復(fù)【plgn】獲取完整源碼


        如果你在運(yùn)行這個(gè)代碼的過程中有遇到問題,請(qǐng)加小編微信xxf960513,我拉你進(jìn)對(duì)應(yīng)微信學(xué)習(xí)群?。椭憧焖僬莆者@個(gè)功能代碼!




        核心代碼介紹

        pom.xml

        ????        <dependency>            <groupId>mysqlgroupId>            <artifactId>mysql-connector-javaartifactId>            <scope>runtimescope>        dependency>
        <dependency> <groupId>org.mybatis.spring.bootgroupId> <artifactId>mybatis-spring-boot-starterartifactId> <version>2.1.1version> dependency>
        <dependency> <groupId>ch.qos.logbackgroupId> <artifactId>logback-coreartifactId> <version>1.1.3version> dependency> <dependency> <groupId>ch.qos.logbackgroupId> <artifactId>logback-accessartifactId> <version>1.1.3version> dependency> <dependency> <groupId>ch.qos.logbackgroupId> <artifactId>logback-classicartifactId> <version>1.1.3version> dependency>
        <dependency> <groupId>org.slf4jgroupId> <artifactId>slf4j-apiartifactId> <version>1.7.25version> dependency> <dependency> <groupId>org.slf4jgroupId> <artifactId>slf4j-simpleartifactId> <version>1.7.25version> <scope>compilescope> dependency>
        <dependency> <groupId>io.springfoxgroupId> <artifactId>springfox-swagger2artifactId> <version>2.9.2version> dependency> <dependency> <groupId>io.swaggergroupId> <artifactId>swagger-modelsartifactId> <version>1.5.21version> dependency> <dependency> <groupId>com.github.xiaoymingroupId> <artifactId>swagger-bootstrap-uiartifactId> <version>1.9.3version> dependency>
        <dependency> <groupId>com.alibabagroupId> <artifactId>fastjsonartifactId> <version>1.2.62version> dependency>
        <dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-testartifactId> <scope>testscope> <exclusions> <exclusion> <groupId>org.junit.vintagegroupId> <artifactId>junit-vintage-engineartifactId> exclusion> exclusions> dependency> dependencies>
        <build> <plugins> <plugin> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-maven-pluginartifactId> plugin> plugins>????build>project>

        application.properties

        server.port=8002spring.datasource.url=jdbc:mysql://xxx.xxx.xxx.xxx:3306/demo?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghaispring.datasource.username=xxxxxxspring.datasource.password=xxxxxxspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

        CommonMapper.java

        package?com.example.demo.mapper;import com.example.demo.vo.ReplyVO;import?org.apache.ibatis.annotations.*;import?java.util.List;@Mapperpublic interface CommonMapper {    @Select("select * from reply_info where comId = #{comId} order by updateTime")????List<ReplyVO>?queryReplyList(@Param("comId")int?comId);    @Delete("delete from reply_info where id = #{id}")    int deleteReply(int id);}

        CommonController.java

        package com.example.demo.controller;import?com.example.demo.service.CommonService;import io.swagger.annotations.Api;import io.swagger.annotations.ApiOperation;import org.springframework.beans.factory.annotation.Autowired;import?org.springframework.web.bind.annotation.*;import java.util.*;
        @Api(description = "文章評(píng)論")@RequestMapping("/common")@RestControllerpublic class CommonController { @Autowired????private?CommonService?commonService; @ApiOperation(value = "獲取文章評(píng)論列表", notes = "獲取文章評(píng)論列表接口") @GetMapping("/replyList/{comId}") public Map getReplyList(@PathVariable("comId") int comId) { List list = commonService.queryReplyList(comId); Map resMap = new HashMap(); resMap.put("STATUS", "0000"); resMap.put("DATA", list); return resMap;????} @ApiOperation(value = "刪除評(píng)論", notes = "刪除評(píng)論接口") @PostMapping("/removeReply/{id}") public Map deleteReply(@PathVariable("id") int id) { commonService.deleteReply(id); Map map = new HashMap(); map.put("STATUS", "0000"); return map; }}

        Home.vue

        <template>  <div class="comment-wrap">    <div v-if="myComment.length" class="comment-list">      <h4>熱門評(píng)論h4>      <div>        <div v-for="(item, index) in myComment" :key="item.id" class="comment-item">          <div class="top-wrap">            <div class="top-left">              <el-image :src="checkImg(item.userId)" alt="" lazy class="top-left-avatar"> el-image>              <div class="top-left-con">                <div class="top-left-con-title">                  <h3>{{ item.userName }}h3>                div>                <div class="top-left-con-time">{{ item.updateTime | moment('YYYY-MM-DD HH:mm') }}div>              div>            div>            <div class="top-right" v-if="loginId === item.userId">              <div class="top-right-item" @click="handleDelete(index)">                <img src="@/assets/delete.png" alt="" />              div>            div>          div>          <div class="label">            {{ item.msg }}          div>
        <div v-if="item.newSub && item.newSub.length" class="reply-wrap"> <div v-for="(reply, i) in item.newSub" :key="reply.id" class="reply-item"> <div class="top-wrap"> <div class="top-left"> <el-image :src="checkImg(reply.userId)" alt="" lazy class="top-left-avatar"> el-image> <div class="top-left-con"> <div class="top-left-con-title"> <h3>{{ reply.userName }}h3> div> <div class="top-left-con-time">{{ reply.updateTime | moment('YYYY-MM-DD HH:mm') }}div> div> div> <div v-if="loginId === reply.userId" class="top-right"> <div class="top-right-item" @click="handleDelete(index, i + 1)"> <img src="@/assets/delete.png" alt="" /> div> div> div> <div class="label"> {{ reply.msg }} div> div> <div v-if="item.subList.length > 1"> <div v-if="!item.isMoreReply" class="showMoreReply" @click="showMoreReply(true, index)">查看更多回復(fù)div> <div v-else class="showMoreReply" @click="showMoreReply(false, index)">收起div> div> div> div> div> div> <el-pagination background :page-size="pageSize" :page-count="pageNo" layout="prev, pager, next" :total="allComment.length" @current-change="handleChangePage" @pre-click="handlePrePage" @next-click="handleNextPage" > el-pagination> div>template>
        <script>import { mapGetters } from 'vuex';import axios from 'axios';export default { components: {}, props: {}, data() { return { textarea: '', isMoreComment: false, replyCon: '', myComment: [], allComment: [], loading: false, pageNo: 1, pageSize: 5 }; }, computed: { ...mapGetters(['loginId']) }, watch: {}, created() {}, mounted() { this.getData(); }, methods: { checkImg(id) { if (id === 1) { return require('@/assets/face.png'); } else { return require('@/assets/comment.png'); } }, showMoreReply(type, index) { this.myComment[index].isMoreReply = type; if (type) { this.myComment[index].newSub = this.myComment[index].subList; } else { this.myComment[index].newSub = this.myComment[index].subList.slice(0, 1); } }, handleDelete(index, i) { console.log(index, i, this.myComment); let id = 0; if (i) { id = this.myComment[index].newSub[i - 1].id; this.myComment[index].newSub.splice(i - 1, 1); } else { id = this.myComment[index].id; this.myComment.splice(index, 1); } axios({ method: 'post', url: `http://xxx.xxx.xxx.xxx:8002/common/removeReply/${id}` }).then(res => { console.log(res, 'res'); }); }, handleChangePage(val) { console.log(val, 'val'); this.pageNo = val; let begin = (val - 1) * this.pageSize;
        this.myComment = this.allComment.slice(begin, begin + this.pageSize); }, handlePrePage() { if (this.pageNo > 1) { this.pageNo--; } let begin = (this.pageNo - 1) * this.pageSize; this.myComment = this.allComment.slice(begin, begin + this.pageSize); }, handleNextPage() { this.pageNo++; let begin = (this.pageNo - 1) * this.pageSize; this.myComment = this.allComment.slice(begin, this.pageSize); }, getData() { axios({ method: 'get', url: `http://xxx.xxx.xxx.xxx:8002/common/replyList/1` }).then(res => { console.log(res, 'res'); let data = res.data.DATA; const list = data.map(item => { return { ...item, newSub: item.subList.slice(0, 1), showReply: false, isMoreReply: false, isMoreComment: false }; });
        console.log(list, 'list'); this.allComment = [].concat(list); this.myComment = list.slice(this.pageNo - 1, this.pageSize); }); } }};

        reply_info.sql

        SET?NAMES?utf8mb4;SET?FOREIGN_KEY_CHECKS?=?0;DROP TABLE IF EXISTS `reply_info`;CREATE TABLE `reply_info` (  `id` int NOT NULL AUTO_INCREMENT,  `userId` int DEFAULT NULL,  `comId` int DEFAULT NULL,  `msg` varchar(255) DEFAULT NULL,  `updatetime` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,  `userName` varchar(255) DEFAULT NULL,  `replyId` int DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
        BEGIN;INSERT INTO `reply_info` VALUES (1, 2, 1, '6', '2020-12-20 22:28:18', '評(píng)論人1', NULL);INSERT INTO `reply_info` VALUES (3, 2, 1, '666', '2020-12-30 22:28:19', '評(píng)論人1', 2);INSERT INTO `reply_info` VALUES (5, 3, 1, '8', '2020-12-20 22:28:29', '評(píng)論人2', NULL);INSERT INTO `reply_info` VALUES (7, 2, 1, '7', '2020-12-20 23:39:19', '評(píng)論人1', NULL);INSERT INTO `reply_info` VALUES (8, 3, 1, '88', '2020-12-30 23:40:12', '評(píng)論人2', 7);INSERT INTO `reply_info` VALUES (11, 3, 1, '8888', '2020-12-31 20:28:21', '評(píng)論人2', 10);INSERT INTO `reply_info` VALUES (12, 1, 1, '88888', '2020-12-31 20:28:35', '發(fā)表人', 11);INSERT INTO `reply_info` VALUES (13, 3, 1, '888888', '2020-12-31 20:28:48', '評(píng)論人2', 12);INSERT INTO `reply_info` VALUES (14, 1, 1, '8888888', '2020-12-31 20:29:06', '發(fā)表人', 13);INSERT INTO `reply_info` VALUES (15, 3, 1, '88888888', '2020-12-31 20:29:22', '評(píng)論人2', 14);INSERT INTO `reply_info` VALUES (17, 4, 1, '4', '2020-12-31 22:08:02', '評(píng)論人4', NULL);INSERT INTO `reply_info` VALUES (19, 5, 1, '5', NULL, '評(píng)論人5', NULL);INSERT INTO `reply_info` VALUES (21, 6, 1, '6', NULL, '評(píng)論人6', NULL);INSERT INTO `reply_info` VALUES (23, 7, 1, '7', NULL, '評(píng)論人7', NULL);INSERT INTO `reply_info` VALUES (24, 1, 1, '77', NULL, '發(fā)表人', 23);INSERT INTO `reply_info` VALUES (25, 8, 1, '8', NULL, '評(píng)論人8', NULL);INSERT INTO `reply_info` VALUES (26, 1, 1, '88', NULL, '發(fā)表人', 25);INSERT INTO `reply_info` VALUES (27, 9, 1, '9', NULL, '評(píng)論人9', NULL);INSERT INTO `reply_info` VALUES (29, 10, 1, '10', NULL, '評(píng)論人10', NULL);INSERT INTO `reply_info` VALUES (31, 11, 1, '11', NULL, '評(píng)論人11', NULL);COMMIT;SET?FOREIGN_KEY_CHECKS?=?1;
        -?END -

        推薦案例

        溫暖提示

        為了方便大家更好的學(xué)習(xí),本公眾號(hào)經(jīng)常分享一些完整的單個(gè)功能案例代碼給大家去練習(xí),如果本公眾號(hào)沒有你要學(xué)習(xí)的功能案例,你可以聯(lián)系小編(微信:xxf960513)提供你的小需求給我,我安排我們這邊的開發(fā)團(tuán)隊(duì)免費(fèi)幫你完成你的案例。
        注意:只能提單個(gè)功能的需求不能要求功能太多,比如要求用什么技術(shù),有幾個(gè)頁面,頁面要求怎么樣?


        請(qǐng)長(zhǎng)按識(shí)別二維碼

        想學(xué)習(xí)更多的java功能案例請(qǐng)關(guān)注

        Java項(xiàng)目開發(fā)

        如果你覺得這個(gè)案例以及我們的分享思路不錯(cuò),對(duì)你有幫助,請(qǐng)分享給身邊更多需要學(xué)習(xí)的朋友。別忘了《留言+點(diǎn)在看》給作者一個(gè)鼓勵(lì)哦!

        瀏覽 76
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        評(píng)論
        圖片
        表情
        推薦
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            欧美有码在线 | 女公安一级毛片放 | 天堂在线视频免费 | 偷偷解开女同桌的内裤摸小说 | 青娱乐 - 亚洲高清视频在线观看 亚洲色逼 | 女人的被男人桶爽网站 | 欧美久久一级 | 五月丁香婷婷亚洲 | 亲摸下的超爽小视频 | 啪视频免费|