云收藏系统|基于Springboot实现云收藏系统
创始人
2024-05-09 01:32:17
0

作者主页:编程指南针

作者简介:Java领域优质创作者、CSDN博客专家 、掘金特邀作者、多年架构师设计经验、腾讯课堂常驻讲师

主要内容:Java项目、毕业设计、简历模板、学习资料、面试题库、技术互助

收藏点赞不迷路  关注作者有好处

文末获取源码 

项目编号:BS-PT-084

一,项目简介

 熟悉浏览器功能的朋友会毫不犹豫,按下CTRL+D健直接归入收藏夹,当然更多的人可能是点开浏览器工具栏—收藏—添加收藏来完成这个工作。

      但目前来看浏览器收藏夹总是让许多人不称心如意,比如不直观、可视性差、无法自由选择打开方式、整理麻烦等。而且当浏览器收藏夹收藏的网站或者文章在一百份以内的时候收藏和查找问题都不是特别大。当收藏大于1000份的时候,去查找自己收藏的内容绝对是个体力活,另外还有一些文章我仅仅只是暂时保存下来,准备随后找时间看看就行,也需要收藏、整理、删除的时候就很麻烦。

      当前的网页浏览器收藏夹存在许多的问题比如不直观、可视性差、无法自由选择打开方式、整理麻烦等,其中最为严重的为以下三点;

      一、收藏栏占地方。它始终停在浏览窗口上端,占用空间,在录屏或者直播时还容易暴露自己的隐私。比如通过下方的收藏栏,别人大致可以裁出用户的职业和喜好来。

      二、收藏夹内容过多时,不能分列。用户喜欢收集很多在线工具,网址越来越多,浏览器收藏夹不能分列,只会把不能显示的隐藏起来,在翻阅网址的时候很不方便。

      三、不能在新标签页打开。点开一个网址,总是在当前窗口打开,将刚才的窗口覆盖掉。这一点很危险,比如你在编辑帖子,突然想打开一个在线工具处理一下图片,结果编辑帖子的页面就消失了,返回后,所有编辑内容消失。虽然配合Ctrl键才能在新标签页打开,但是极度专注的情况下很容易忘记。

      通过上面的问题介绍,也就很好的表明了本系统的研究目的。本系统不仅仅只解决了原有的问题矛盾,还能让大家可以在收藏时看看别人所收藏的网站可以进行互动分享,然后感兴趣的网站自己也可以进行收藏保存。

      本系统的具体功能模块包括:前端登录界面,用户后台界面、以及管理员后台界面。设计的功能模块包括账号管理模块、互动管理模块、导入导出模块、回收站模块、收藏夹模块、收藏管理模块、搜索管理模块、管理员管理模块等功能。

二,环境介绍

语言环境:Java:  jdk1.8

数据库:Mysql: mysql5.7

应用服务器:Tomcat:  tomcat8.5.31

开发工具:IDEA或eclipse

后台开发技术:Springboot

前台开发技术:css+js+html+bootstrap

三,系统展示

系统首页

瞅瞅别人公开的收藏网站

用户注册

用户登陆

个人后台管理中心

未读收藏列表

删除或修改收藏目录

收藏夹管理

发现浏览别人新的收藏

互动管理

导入导出收藏文件:可以将浏览器中导出的收藏导入进来,也可以将本系统收藏进行导出来HTML

查看互动通知:可以点赞、收藏、关注、私信

维护个人信息

查看别人收藏空间,并进行互动

四,核心代码展示

package com.favorites.web;import com.favorites.cache.CacheService;
import com.favorites.comm.Const;
import com.favorites.comm.aop.LoggerManage;
import com.favorites.domain.Collect;
import com.favorites.domain.Favorites;
import com.favorites.domain.Praise;
import com.favorites.domain.enums.CollectType;
import com.favorites.domain.enums.IsDelete;
import com.favorites.domain.result.ExceptionMsg;
import com.favorites.domain.result.Response;
import com.favorites.domain.view.CollectSummary;
import com.favorites.repository.CollectRepository;
import com.favorites.repository.FavoritesRepository;
import com.favorites.repository.PraiseRepository;
import com.favorites.service.CollectService;
import com.favorites.service.FavoritesService;
import com.favorites.service.LookAroundService;
import com.favorites.service.LookRecordService;
import com.favorites.utils.DateUtils;
import com.favorites.utils.HtmlUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;@RestController
@RequestMapping("/collect")
public class CollectController extends BaseController{@Autowiredprivate CollectRepository collectRepository;@Resourceprivate FavoritesService favoritesService;@Resourceprivate CollectService collectService;@Resourceprivate FavoritesRepository favoritesRepository;@Resourceprivate PraiseRepository praiseRepository;@Autowiredprivate CacheService cacheService;/*** 随便看看*/@Autowiredprivate LookAroundService lookAroundService;/*** 浏览记录*/@Autowiredprivate LookRecordService lookRecordService;/*** 文章收集* @param collect* @return*/@RequestMapping(value = "/collect", method = RequestMethod.POST)@LoggerManage(description="文章收集")public Response collect(Collect collect) {		try {if(StringUtils.isBlank(collect.getLogoUrl()) || collect.getLogoUrl().length()>300){collect.setLogoUrl(Const.BASE_PATH + Const.default_logo);}collect.setUserId(getUserId());if(collectService.checkCollect(collect)){Collect exist=collectRepository.findByIdAndUserId(collect.getId(), collect.getUserId());if(collect.getId()==null){collectService.saveCollect(collect);}else if(exist==null){//收藏别人的文章collectService.otherCollect(collect);}else{collectService.updateCollect(collect);}}else{return result(ExceptionMsg.CollectExist);}} catch (Exception e) {// TODO: handle exceptionlogger.error("collect failed, ", e);return result(ExceptionMsg.FAILED);}return result();}@RequestMapping(value="/getCollectLogoUrl",method=RequestMethod.POST)@LoggerManage(description="获取收藏页面的LogoUrl")public String getCollectLogoUrl(String url){if(StringUtils.isNotBlank(url)){String logoUrl = cacheService.getMap(url);if(StringUtils.isNotBlank(logoUrl)){return logoUrl;}else{return Const.default_logo;}}else{return Const.default_logo;}}/*** 根据收藏的文章标题和描述推荐收藏夹*/@RequestMapping(value="/getFavoriteResult",method=RequestMethod.POST)@LoggerManage(description="获取推荐收藏夹")public Map getFavoriteResult(String title,String description){Long result = null;int faultPosition = 0;Map maps = new HashMap();List favoritesList = this.favoritesRepository.findByUserIdOrderByLastModifyTimeDesc(getUserId());for (int i = 0; i < favoritesList.size(); i++){Favorites favorites = favoritesList.get(i);if(favorites.getName().indexOf(title) > 0 || favorites.getName().indexOf(description) > 0){result = favorites.getId();}if("未读列表".equals(favorites.getName())){faultPosition = i;}}result = result == null ? favoritesList.get(faultPosition).getId() : result;maps.put("favoritesResult",result == null ? 0 : result);maps.put("favoritesList",favoritesList);return maps;}/*** @param page* @param size* @param type* @return*/@RequestMapping(value="/standard/{type}/{favoritesId}/{userId}/{category}")@LoggerManage(description="文章列表standard")public List standard(@RequestParam(value = "page", defaultValue = "0") Integer page,@RequestParam(value = "size", defaultValue = "15") Integer size,@PathVariable("type") String type,@PathVariable("favoritesId") Long favoritesId,@PathVariable("userId") Long userId,@PathVariable("category") String category) {Sort sort = new Sort(Direction.DESC, "id");Pageable pageable = PageRequest.of(page, size,sort);List collects = null;if("otherpublic".equalsIgnoreCase(type)){if(null != favoritesId && 0 != favoritesId){collects = collectService.getCollects(type, userId, pageable, favoritesId,getUserId());}else{collects = collectService.getCollects("others", userId, pageable, null,getUserId());}}else if(category != null && !"".equals(category) && !"NO".equals(category)){//用于随便看看功能中收藏列表显示collects = lookAroundService.queryCollectExplore(pageable,getUserId(),category);}else if(type != null && !"".equals(type) && "lookRecord".equals(type)){//用于浏览记录功能中收藏列表显示collects =lookRecordService.getLookRecords(this.getUserId(),pageable);}else{if(null != favoritesId && 0 != favoritesId){collects = collectService.getCollects(String.valueOf(favoritesId),getUserId(), pageable,null,null);}else{collects=collectService.getCollects(type,getUserId(), pageable,null,null);}}return collects;}@RequestMapping(value="/lookAround")@LoggerManage(description="查看更多lookAround")public List lookAround(@RequestParam(value = "page", defaultValue = "0") Integer page,@RequestParam(value = "size", defaultValue = "15") Integer size) {Sort sort = new Sort(Direction.DESC, "id");Pageable pageable = PageRequest.of(page, size, sort);List collects =lookAroundService.queryCollectExplore(pageable, getUserId(),null);return collects;}/*** @param page* @param size* @param type* @return*/@RequestMapping(value="/simple/{type}/{favoritesId}/{userId}/{category}")@LoggerManage(description="文章列表simple")public List simple(@RequestParam(value = "page", defaultValue = "0") Integer page,@RequestParam(value = "size", defaultValue = "15") Integer size,@PathVariable("type") String type,@PathVariable("favoritesId") Long favoritesId,@PathVariable("userId") Long userId,@PathVariable("category") String category) {Sort sort = new Sort(Direction.DESC, "id");Pageable pageable = PageRequest.of(page, size,sort);List collects = null;if("otherpublic".equalsIgnoreCase(type)){if(null != favoritesId && 0 != favoritesId){collects = collectService.getCollects(type, userId, pageable, favoritesId,getUserId());}else{collects = collectService.getCollects("others", userId, pageable, null,getUserId());}}else if(category != null && !"".equals(category) && !"NO".equals(category)){//用于随便看看功能中收藏列表显示collects = lookAroundService.queryCollectExplore(pageable,getUserId(),category);}else{if(null != favoritesId && 0 != favoritesId){collects = collectService.getCollects(String.valueOf(favoritesId),getUserId(), pageable,null,null);}else{collects = collectService.getCollects(type,getUserId(), pageable,null,null);}}return collects;}/*** @param id* @param type*/@RequestMapping(value="/changePrivacy/{id}/{type}")public Response changePrivacy(@PathVariable("id") long id,@PathVariable("type") CollectType type) {collectRepository.modifyByIdAndUserId(type, id, getUserId());return result();}/*** like and unlike* @param id* @return*/@RequestMapping(value="/like/{id}")@LoggerManage(description="文章点赞或者取消点赞")public Response like(@PathVariable("id") long id) {try {collectService.like(getUserId(), id);} catch (Exception e) {// TODO: handle exceptionlogger.error("文章点赞或者取消点赞异常:",e);}return result();}/*** @param id* @return*/@RequestMapping(value="/delete/{id}")public Response delete(@PathVariable("id") long id) {Collect collect = collectRepository.findById(id);if(null != collect && getUserId()==collect.getUserId()){collectRepository.deleteById(id);if(null != collect.getFavoritesId() && !IsDelete.YES.equals(collect.getIsDelete())){favoritesRepository.reduceCountById(collect.getFavoritesId(), DateUtils.getCurrentTime());}}return result();}/*** @param id* @return*/@RequestMapping(value="/detail/{id}")public Collect detail(@PathVariable("id") long id) {Collect collect=collectRepository.findById(id);return collect;}/*** 导入收藏夹**/@RequestMapping("/import")@LoggerManage(description="导入收藏夹操作")public void importCollect(@RequestParam("htmlFile") MultipartFile htmlFile,String structure,String type){try {if(StringUtils.isNotBlank(structure)&& IsDelete.YES.toString().equals(structure)){// 按照目录结构导入Map> map = HtmlUtil.parseHtmlTwo(htmlFile.getInputStream());if(null == map || map.isEmpty()){logger.info("未获取到url连接");return ;}for (Entry> entry : map.entrySet()) {  String favoritesName = entry.getKey();Favorites favorites = favoritesRepository.findByUserIdAndName(getUserId(), favoritesName);if(null == favorites){favorites = favoritesService.saveFavorites(getUserId(), favoritesName);}collectService.importHtml(entry.getValue(), favorites.getId(), getUserId(),type);} }else{Map map = HtmlUtil.parseHtmlOne(htmlFile.getInputStream());if(null == map || map.isEmpty()){logger.info("未获取到url连接");return ;}// 全部导入到<导入自浏览器>收藏夹Favorites favorites = favoritesRepository.findByUserIdAndName(getUserId(), "导入自浏览器");if(null == favorites){favorites = favoritesService.saveFavorites(getUserId(),"导入自浏览器");}collectService.importHtml(map, favorites.getId(), getUserId(),type);}} catch (Exception e) {logger.error("导入html异常:",e);}}/*** 导出收藏夹* @param favoritesId* @return*/@RequestMapping("/export")@LoggerManage(description="导出收藏夹操作")public void export(String favoritesId,HttpServletResponse response){if(StringUtils.isNotBlank(favoritesId)){try {String[] ids = favoritesId.split(",");String date = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());String fileName= "favorites_" + date + ".html";StringBuilder sb = new StringBuilder();for(String id : ids){try {sb = sb.append(collectService.exportToHtml(Long.parseLong(id)));} catch (Exception e) {logger.error("异常:",e);}}sb = HtmlUtil.exportHtml("云收藏夹", sb);response.setCharacterEncoding("UTF-8");  response.setHeader("Content-disposition","attachment; filename=" + fileName);response.getWriter().print(sb);} catch (Exception e) {logger.error("异常:",e);}}}@RequestMapping(value="/searchMy/{key}")public List searchMy(Model model,@RequestParam(value = "page", defaultValue = "0") Integer page,@RequestParam(value = "size", defaultValue = "20") Integer size, @PathVariable("key") String key) {Sort sort = new Sort(Direction.DESC, "id");Pageable pageable = PageRequest.of(page, size,sort);List myCollects=collectService.searchMy(getUserId(),key ,pageable);model.addAttribute("myCollects", myCollects);logger.info("searchMy end :");return myCollects;}@RequestMapping(value="/searchOther/{key}")public List searchOther(Model model,@RequestParam(value = "page", defaultValue = "0") Integer page,@RequestParam(value = "size", defaultValue = "20") Integer size, @PathVariable("key") String key) {Sort sort = new Sort(Direction.DESC, "id");Pageable pageable = PageRequest.of(page, size,sort);List otherCollects=collectService.searchOther(getUserId(), key, pageable);logger.info("searchOther end :");return otherCollects;}/*** 查询点赞状态及该文章的点赞数量*/@RequestMapping(value="/getPaiseStatus/{collectId}")public Map getPraiseStatus(Model model,@PathVariable("collectId") Long collectId){Map maps = new HashMap();Praise praise = praiseRepository.findByUserIdAndCollectId(getUserId(), collectId);Long praiseCount = praiseRepository.countByCollectId(collectId);maps.put("status",praise != null ? "praise" : "unpraise");maps.put("praiseCount",praiseCount);return maps;}}
package com.favorites.web;import java.util.List;import javax.annotation.Resource;import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import com.favorites.domain.Collect;
import com.favorites.domain.Comment;
import com.favorites.domain.User;
import com.favorites.domain.result.Response;
import com.favorites.repository.CollectRepository;
import com.favorites.repository.CommentRepository;
import com.favorites.repository.UserRepository;
import com.favorites.service.NoticeService;
import com.favorites.utils.DateUtils;
import com.favorites.utils.StringUtil;@RestController
@RequestMapping("/comment")
public class CommentController extends BaseController{@Autowiredprivate  CommentRepository CommentRepository;@Autowiredprivate UserRepository userRepository;@Resourceprivate NoticeService noticeService;@Autowiredprivate CollectRepository colloectRepository;/*** @param comment评论* @return*/@RequestMapping(value="/add")public Response add(Comment comment) {User user = null;if (comment.getContent().indexOf("@") > -1) {List atUsers = StringUtil.getAtUser(comment.getContent());if(atUsers!=null && atUsers.size()>0){user = userRepository.findByUserName(atUsers.get(0));if (null != user) {comment.setReplyUserId(user.getId());} else {logger.info("为找到匹配:" + atUsers.get(0) + "的用户.");}String content=comment.getContent().substring(0,comment.getContent().indexOf("@"));if(StringUtils.isBlank(content)){content=comment.getContent().substring(comment.getContent().indexOf("@")+user.getUserName().length()+1,comment.getContent().length());}comment.setContent(content);}}comment.setUserId(getUserId());comment.setCreateTime(DateUtils.getCurrentTime());CommentRepository.save(comment);if(null != user){// 保存消息通知(回复)noticeService.saveNotice(String.valueOf(comment.getCollectId()), "comment", user.getId(), String.valueOf(comment.getId()));}else{// 保存消息通知(直接评论)Collect collect = colloectRepository.findById((long)comment.getCollectId());if(null != collect){noticeService.saveNotice(String.valueOf(comment.getCollectId()), "comment", collect.getUserId(), String.valueOf(comment.getId()));}}return result();}/*** @param collectId* @return*/@RequestMapping(value="/list/{collectId}")public List list(@PathVariable("collectId") long collectId) {List comments= CommentRepository.findByCollectIdOrderByIdDesc(collectId);return convertComment(comments);}/*** @param id* @return*/@RequestMapping(value="/delete/{id}")public Response delete(@PathVariable("id") long id) {CommentRepository.deleteById(id);return result();}/*** 转化时间和用户名* @param comments* @return*/private List convertComment(List comments) {for (Comment comment : comments) {User user = userRepository.findById((long)comment.getUserId());comment.setCommentTime(DateUtils.getTimeFormatText(comment.getCreateTime()));comment.setUserName(user.getUserName());comment.setProfilePicture(user.getProfilePicture());if(comment.getReplyUserId()!=null && comment.getReplyUserId()!=0){User replyUser = userRepository.findById((long)comment.getReplyUserId());comment.setReplyUserName(replyUser.getUserName());}}return comments;}}

五,项目总结

整个系统的开发和实现还是比较有创意的,它很好的解决本地浏览器信息收藏的不方便性,可以通过本次开发的云收藏系统和浏览收藏信息进行共享,并在平台中进行有效的管理和共享,功能还是比较实用且齐全的,是一个优秀的毕业设计项目。系统使用Springboot框架开发,整个界面设计十很简洁大方。

相关内容

热门资讯

MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
操作系统面试题(史上最全、持续... 尼恩面试宝典专题40:操作系统面试题(史上最全、持续更新)...
Android---Banne... 轮播图是一种很常见的UI。Banner框架能够帮助我们快速开发,完成首页轮播图效果的需...
python -- PyQt5... 控件2 本章我们继续介绍PyQt5控件。这次的有 QPixmap , QLineEdi...
Mysql SQL优化跟踪来看... 背景 使用索引字段进行筛选数据时,explain查询语句发现MySQL居然没有使用索...
UG 6.0软件安装教程 UG 6.0软件安装教程 软件简介: UG 6.0是目前网络最好用、使用最为广泛的大型...
HTML静态网页作业——关于我... 家乡旅游景点网页作业制作 网页代码运用了DIV盒子的使用方法,如盒子的嵌套、浮动、ma...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...
NoSQL数据库之Redis2 Redis 事务 事务的基础概念 关于事务最常见的例子就是银行转账,A 账户给 B 账...
Spring Security... 前言 在 Spring Security 中,默认的登陆方式是以表单形式进行提交参数的...