云收藏系统|基于Springboot实现云收藏系统

Posted 编程指南针

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了云收藏系统|基于Springboot实现云收藏系统相关的知识,希望对你有一定的参考价值。

作者主页:编程指南针

作者简介: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
	@Autowired
	private CollectRepository collectRepository;
	@Resource
	private FavoritesService favoritesService;
	@Resource
	private CollectService collectService;
	@Resource
	private FavoritesRepository favoritesRepository;
	@Resource
	private PraiseRepository praiseRepository;

	@Autowired
	private CacheService cacheService;

	/**
	 * 随便看看
	 */
	@Autowired
	private LookAroundService lookAroundService;

	/**
	 * 浏览记录
	 */
	@Autowired
	private 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 exception
			logger.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<String,Object> getFavoriteResult(String title,String description)
		Long result = null;
		int faultPosition = 0;
		Map<String,Object> maps = new HashMap<String,Object>();
		List<Favorites> 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<CollectSummary> 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<CollectSummary> 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<CollectSummary> 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<CollectSummary> 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<CollectSummary> 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<CollectSummary> 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 exception
			logger.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<String, Map<String, String>> map = HtmlUtil.parseHtmlTwo(htmlFile.getInputStream());
				if(null == map || map.isEmpty())
					logger.info("未获取到url连接");
					return ;
				
				for (Entry<String, Map<String, String>> 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<String, String> 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<CollectSummary> 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<CollectSummary> myCollects=collectService.searchMy(getUserId(),key ,pageable);
		model.addAttribute("myCollects", myCollects);
		logger.info("searchMy end :");
		return myCollects;
	
	
	@RequestMapping(value="/searchOther/key")
	public List<CollectSummary> 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<CollectSummary> otherCollects=collectService.searchOther(getUserId(), key, pageable);
		logger.info("searchOther end :");
		return otherCollects;
	

	/**
	 * 查询点赞状态及该文章的点赞数量
	 */
	@RequestMapping(value="/getPaiseStatus/collectId")
	public Map<String,Object> getPraiseStatus(Model model,@PathVariable("collectId") Long collectId)
		Map<String,Object> maps = new HashMap<String,Object>();
		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
	
	@Autowired
	private  CommentRepository CommentRepository;
	@Autowired
	private UserRepository userRepository;
	@Resource
	private NoticeService noticeService;
	@Autowired
	private CollectRepository colloectRepository;
	
	
	/**
	 * @param comment评论
	 * @return
	 */
	@RequestMapping(value="/add")
	public Response add(Comment comment) 
		User user = null;
		if (comment.getContent().indexOf("@") > -1) 
			List<String> 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<Comment> list(@PathVariable("collectId") long collectId) 
		List<Comment> 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<Comment> convertComment(List<Comment> 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框架开发,整个界面设计十很简洁大方。

以上是关于云收藏系统|基于Springboot实现云收藏系统的主要内容,如果未能解决你的问题,请参考以下文章

基于Java+Springboot+Vue+elememt社区疫情返乡管控系统设计实现

基于Java+Springboot+Vue+elememt社区疫情返乡管控系统设计实现

Git上热门的springboot开源项目

基于Java+Springboot+Vue+elememt甜品屋蛋糕商城系统设计和实现

基于Java+Springboot+Vue+elememt甜品屋蛋糕商城系统设计和实现

基于Java+SpringBoot+vue等疫情期间网课管理系统详细设计和实现