Implements a level-2 comment system (like a simplified book) based on Angularjs + mybatis, and angularjsmybatis

Source: Internet
Author: User

Implements a level-2 comment system (like a simplified book) based on Angularjs + mybatis, and angularjsmybatis

I always wanted to write a comment system. I read more about the comments of Netease And jianshu and thought about what kind of comment system I should implement.

The key to the comment system is the nested layers and database table design. The number of nested layers is large, the table structure is complex, and presentation is troublesome. Finally, it is decided to implement a second-level comment. The system is built by maven, and springboot quickly builds the spring environment. Angularjs + bootstrap are used at the front end, springmvc + mybatis is used at the backend, and MySQL is used for the database. The front end requests the background API for comments.

Directory structure

Database Table Design

# 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;

Get comments mapper (key)

<?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> 

Page display


The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.