请基于mysql设计表,初步实现一个发帖回帖系统,简要说明表的设计思路,给出表结构。
如果需要创建索引,则要说明在索引类型和索引建立的字段。
设计时需要考虑如下业务:
1、用户发主题帖
2、用户针对主题帖的回帖
3、查询指定时间范围内指定用户的所有发帖回帖记录
4、统计主题帖的浏览量
5、统计主题帖的回复量
6、用户删除自己的帖子(主题帖或回帖)
发帖 posts
CREATE TABLE `posts` (
`p_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '帖子的id',
`u_id` int(11) NOT NULL COMMENT '用户人的id',
`p_title` varchar(50) NOT NULL COMMENT '帖子的标题',
`p_createtime` datetime NOT NULL,
`p_updatetime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP COMMENT '帖子更新的时间',
`p_content` text NOT NULL COMMENT '帖子的内容',
`p_clickcount` int(255) NOT NULL DEFAULT '0' COMMENT '帖子的点击次数',
`p_goodcount` int(255) DEFAULT '0' COMMENT '帖子的好评数',
`p_badcount` int(255) DEFAULT '0' COMMENT '帖子的坏评数',
`p_reward` int(50) DEFAULT NULL COMMENT '帖子的总共赏分',
`p_ispay` tinyint(2) DEFAULT '0' COMMENT '是否结贴:0 否 1 是',
PRIMARY KEY (`p_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='发帖';
回复表replys
CREATE TABLE `replys` (
`r_replyid` int(11) NOT NULL AUTO_INCREMENT,
`r_postid` int(11) NOT NULL COMMENT '回复的帖子id',
`u_id` int(11) NOT NULL COMMENT '回复者的姓名',
`r_content` varchar(255) NOT NULL COMMENT '回复的内容',
`r_createtime` datetime NOT NULL COMMENT '回复创建的时间',
`r_goodcount` int(16) DEFAULT NULL COMMENT '回复的好评数',
`r_badcount` int(16) DEFAULT NULL COMMENT '回复的坏评数',
`r_score` int(16) DEFAULT NULL COMMENT '回复所得到的积分',
PRIMARY KEY (`r_replyid`),
KEY `fk2` (`r_postid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='回复';
用户表users
CREATE TABLE `users` (
`u_id` int(11) NOT NULL AUTO_INCREMENT,
`u_head` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL COMMENT '用户的头像',
`u_name` varchar(25) NOT NULL,
`u_password` varchar(25) NOT NULL,
`u_email` varchar(25) DEFAULT NULL,
`u_birthday` datetime(6) DEFAULT NULL,
`u_sex` tinyint(2) DEFAULT '0' COMMENT '用户的性别:0男 1女',
`u_role` int(8) DEFAULT NULL COMMENT '用户角色',
PRIMARY KEY (`u_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户表';
如果两个集合的元素个数相同且对应元素相同,则称集合相同。
请用尽肯能高效的方法判断集合A和集合B是否相同。
/**
* 使用list自带的sort方法先进性排序,然后转成toString去判断两个集合是否相等
* 方法6
*/
private static boolean checkDiffrent5(List<String> list, List<String> list1) {
long st = System.nanoTime();
System.out.println("消耗时间为: " + (System.nanoTime() - st));
list.sort(Comparator.comparing(String::hashCode));
list1.sort(Comparator.comparing(String::hashCode));
return list.toString().equals(list1.toString());
}
}
实现String类的indexOf()方法,输入2个长度不定的字符串,str1,str2,返回str2在str1中第一次出现的位置。
str2.indexof(str1,1)