当前位置: 移动技术网 > IT编程>脚本编程>AngularJs > 基于Angularjs+mybatis实现二级评论系统(仿简书)

基于Angularjs+mybatis实现二级评论系统(仿简书)

2018年05月01日  | 移动技术网IT编程  | 我要评论

一直想写个评论系统,看了下多说,网易,简书的评论,想了下自己该实现怎样的评论系统。

评论系统关键是嵌套层数以及数据库表设计。嵌套层数多,表结构复杂,呈现也麻烦,最后决定实现一个二级评论。系统由maven构建,springboot快速搭建spring环境。前台采用angularjs+bootstrap,后台使用springmvc+mybatis,数据库采用mysql.前台请求后台api操作评论。

目录结构

数据库表设计

##说说表或者文章表 
create table saying ( 
 saying_id int not null auto_increment primary key, 
 sayingcontent varchar(500) not null, 
 author varchar(50) not null, 
 sayingavatar varchar(50) not null, 
 likes varchar(500) not null, 
 createtime datetime not null 
) engine=innodb default charset=utf8; 
 
##一级评论表 
create table firstlevelcomment ( 
 flc_id int not null auto_increment primary key, 
 sayingid int not null, 
 commenter varchar(50) not null, 
 commenteravatar varchar(50) not null, 
 commentcontent varchar(500) not null, 
 commenttime datetime not null 
) engine=innodb default charset=utf8; 
 
##二级评论表 
create table secondlevelcomment ( 
 slc_id int not null auto_increment primary key, 
 sayingid int not null, 
 flcid int not null, 
 replier varchar(50) not null, 
 tocommenter varchar(50) not null, 
 replycontent varchar(50) not null, 
 replytime datetime not null 
) engine=innodb default charset=utf8; 

获取评论的mapper(关键)

<?xml version="1.0" encoding="utf-8" ?> 
<!doctype mapper public "-//mybatis.org//dtd mapper 3.0//en" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > 
<mapper namespace="personal.timeless.cms.mapper.sayingmapper" > 
 
 <resultmap id="sayingmap" type="saying" > 
 <id column="saying_id" property="id" jdbctype="integer" /> 
 <result column="sayingcontent" property="sayingcontent" jdbctype="integer" /> 
 <result column="author" property="author" jdbctype="varchar" /> 
 <result column="sayingavatar" property="avatar" jdbctype="varchar" /> 
 <result column="likes" property="likes" jdbctype="varchar" /> 
 <result column="createtime" property="createtime" jdbctype="timestamp" /> 
 <collection property="flcs" oftype="firstlevelcomment" column="sayingid"> 
 <id column="flc_id" property="id" jdbctype="integer" /> 
 <result column="sayingid" property="sayingid" jdbctype="integer" /> 
 <result column="commenter" property="commenter"/> 
 <result column="commenteravatar" property="avatar"/> 
 <result column="commentcontent" property="commentcontent"/> 
 <result column="commenttime" property="commenttime" jdbctype="timestamp" /> 
 <collection property="slcs" oftype="secondlevelcomment" column="flcid"> 
  <id column="slc_id" property="id" jdbctype="integer" /> 
  <result column="flcid" property="flcid" jdbctype="integer" /> 
  <result column="replier" property="replier"/> 
  <result column="tocommenter" property="tocommenter"/> 
  <result column="replycontent" property="replycontent"/> 
  <result column="replytime" property="replytime" jdbctype="timestamp" /> 
 </collection> 
 </collection> 
 </resultmap> 
 
 <select id="selectonebyid" resultmap="sayingmap" parametertype="int" > 
 select * from 
 (select * from saying s left join firstlevelcomment fc on s.saying_id=fc.sayingid where s.saying_id=#{id}) tmp left join secondlevelcomment sc 
 on tmp.flc_id = sc.flcid 
 </select> 
 
 <select id="updatelikesbyid"> 
 update saying set likes = #{likes} where saying_id = #{id} 
 </select> 
 </mapper> 

页面展示


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网