首页 / MYSQL / 关于tag标签系统的实现
关于tag标签系统的实现
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了关于tag标签系统的实现,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2022字,纯文字阅读大概需要3分钟。
内容图文
![关于tag标签系统的实现](/upload/InfoBanner/zyjiaocheng/532/39482f249a1d4933b6f9396b7dc80881.jpg)
实验室的项目,需要做对用户发布的主题进行打标签的功能,纠结甚久,实现思路如下: 一、数据库表的设计 1.tag表 create table qa_tag(tag_id int primary key auto_increment,tag_name varchar(32) not null,tag_time timestamp not null default CURRENT_T
实验室的项目,需要做对用户发布的主题进行打标签的功能,纠结甚久,实现思路如下:
一、数据库表的设计
1.tag表
create table qa_tag ( tag_id int primary key auto_increment, tag_name varchar(32) not null, tag_time timestamp not null default CURRENT_TIMESTAMP, refered_cnt int not null default 0, user_id int not null, unique (tag_name), constraint foreign key (user_id) references user_info(user_id) ); 2.topic表
create table qa_topic ( topic_id int primary key auto_increment, topic_title varchar(128) not null, topic_body text not null, topic_time timestamp not null default CURRENT_TIMESTAMP, user_id int not null, tags varchar(128) not null default '' );3.tag与topic的映射表
create table qa_tag_topic
(
record_id int primary key auto_increment,
tag_id int not null,
topic_id int not null,
constraint foreign key (tag_id) references qa_tag(tag_id),
constraint foreign key (topic_id) references qa_topic(topic_id)
);
1.用户创建主题时,给自己发布的主题打上了几个标签,点击提交
2.后台接受参数后,先把数据插入到qa_topic表中,获得了topicId;
3.把用户输入的标签转成数组,批量插入到数据库中,sql代码如下:
insert into qa_tag(tag_name,user_id) values (#{o.tagName},#{o.userId}) ON DUPLICATE KEY UPDATE refered_cnt = refered_cnt + 1;//如果有重复,则把tag的被引用数目+1 alter table qa_tag auto_increment = 1//保证tagId的连续性
4. 根据标签数组,查询插入后,这些标签的tagId(返回一个链表):
5.然后,把tagId和topicId批量插入到qa_tag_topic:
insert ignore into qa_tag_topic(tag_id,topic_id) values
(#{o.tagId},#{o.topicId})
6.把topicId返回即可。
内容总结
以上是互联网集市为您收集整理的关于tag标签系统的实现全部内容,希望文章能够帮你解决关于tag标签系统的实现所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。