这次给大家带来用angularjs+mybatis做出评论系统,用angularjs+mybatis做评论系统的注意事项有哪些?下面就是实战案例,一起来看一下。
一直想写个评论系统,看了下多说,网易,简书的评论,想了下自己该实现怎样的评论系统。评论系统关键是嵌套层数以及数据库表设计。嵌套层数多,表结构复杂,呈现也麻烦,最后决定实现一个二级评论。系统由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>
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
相关阅读:
使用pixi.js的总结
在python中如何执行execjs语句
在vue首页怎样做出底部导航tabbar
用video.js实现h5直播界面
以上就是用angularjs+mybatis做出评论系统的详细内容。