小言_互联网的博客

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

337人阅读  评论(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

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

维护个人信息

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

四,核心代码展示


  
  1. package com.favorites.web;
  2. import com.favorites.cache.CacheService;
  3. import com.favorites.comm.Const;
  4. import com.favorites.comm.aop.LoggerManage;
  5. import com.favorites.domain.Collect;
  6. import com.favorites.domain.Favorites;
  7. import com.favorites.domain.Praise;
  8. import com.favorites.domain.enums.CollectType;
  9. import com.favorites.domain.enums.IsDelete;
  10. import com.favorites.domain.result.ExceptionMsg;
  11. import com.favorites.domain.result.Response;
  12. import com.favorites.domain.view.CollectSummary;
  13. import com.favorites.repository.CollectRepository;
  14. import com.favorites.repository.FavoritesRepository;
  15. import com.favorites.repository.PraiseRepository;
  16. import com.favorites.service.CollectService;
  17. import com.favorites.service.FavoritesService;
  18. import com.favorites.service.LookAroundService;
  19. import com.favorites.service.LookRecordService;
  20. import com.favorites.utils.DateUtils;
  21. import com.favorites.utils.HtmlUtil;
  22. import org.apache.commons.lang3.StringUtils;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.data.domain.PageRequest;
  25. import org.springframework.data.domain.Pageable;
  26. import org.springframework.data.domain.Sort;
  27. import org.springframework.data.domain.Sort.Direction;
  28. import org.springframework.ui.Model;
  29. import org.springframework.web.bind.annotation.*;
  30. import org.springframework.web.multipart.MultipartFile;
  31. import javax.annotation.Resource;
  32. import javax.servlet.http.HttpServletResponse;
  33. import java.text.SimpleDateFormat;
  34. import java.util.Date;
  35. import java.util.HashMap;
  36. import java.util.List;
  37. import java.util.Map;
  38. import java.util.Map.Entry;
  39. @RestController
  40. @RequestMapping("/collect")
  41. public class CollectController extends BaseController{
  42. @Autowired
  43. private CollectRepository collectRepository;
  44. @Resource
  45. private FavoritesService favoritesService;
  46. @Resource
  47. private CollectService collectService;
  48. @Resource
  49. private FavoritesRepository favoritesRepository;
  50. @Resource
  51. private PraiseRepository praiseRepository;
  52. @Autowired
  53. private CacheService cacheService;
  54. /**
  55. * 随便看看
  56. */
  57. @Autowired
  58. private LookAroundService lookAroundService;
  59. /**
  60. * 浏览记录
  61. */
  62. @Autowired
  63. private LookRecordService lookRecordService;
  64. /**
  65. * 文章收集
  66. * @param collect
  67. * @return
  68. */
  69. @RequestMapping(value = "/collect", method = RequestMethod.POST)
  70. @LoggerManage(description="文章收集")
  71. public Response collect (Collect collect) {
  72. try {
  73. if(StringUtils.isBlank(collect.getLogoUrl()) || collect.getLogoUrl().length()> 300){
  74. collect.setLogoUrl(Const.BASE_PATH + Const.default_logo);
  75. }
  76. collect.setUserId(getUserId());
  77. if(collectService.checkCollect(collect)){
  78. Collect exist=collectRepository.findByIdAndUserId(collect.getId(), collect.getUserId());
  79. if(collect.getId()== null){
  80. collectService.saveCollect(collect);
  81. } else if(exist== null){ //收藏别人的文章
  82. collectService.otherCollect(collect);
  83. } else{
  84. collectService.updateCollect(collect);
  85. }
  86. } else{
  87. return result(ExceptionMsg.CollectExist);
  88. }
  89. } catch (Exception e) {
  90. // TODO: handle exception
  91. logger.error( "collect failed, ", e);
  92. return result(ExceptionMsg.FAILED);
  93. }
  94. return result();
  95. }
  96. @RequestMapping(value="/getCollectLogoUrl",method=RequestMethod.POST)
  97. @LoggerManage(description="获取收藏页面的LogoUrl")
  98. public String getCollectLogoUrl (String url){
  99. if(StringUtils.isNotBlank(url)){
  100. String logoUrl = cacheService.getMap(url);
  101. if(StringUtils.isNotBlank(logoUrl)){
  102. return logoUrl;
  103. } else{
  104. return Const.default_logo;
  105. }
  106. } else{
  107. return Const.default_logo;
  108. }
  109. }
  110. /**
  111. * 根据收藏的文章标题和描述推荐收藏夹
  112. */
  113. @RequestMapping(value="/getFavoriteResult",method=RequestMethod.POST)
  114. @LoggerManage(description="获取推荐收藏夹")
  115. public Map<String,Object> getFavoriteResult (String title,String description){
  116. Long result = null;
  117. int faultPosition = 0;
  118. Map<String,Object> maps = new HashMap<String,Object>();
  119. List<Favorites> favoritesList = this.favoritesRepository.findByUserIdOrderByLastModifyTimeDesc(getUserId());
  120. for ( int i = 0; i < favoritesList.size(); i++){
  121. Favorites favorites = favoritesList.get(i);
  122. if(favorites.getName().indexOf(title) > 0 || favorites.getName().indexOf(description) > 0){
  123. result = favorites.getId();
  124. }
  125. if( "未读列表".equals(favorites.getName())){
  126. faultPosition = i;
  127. }
  128. }
  129. result = result == null ? favoritesList.get(faultPosition).getId() : result;
  130. maps.put( "favoritesResult",result == null ? 0 : result);
  131. maps.put( "favoritesList",favoritesList);
  132. return maps;
  133. }
  134. /**
  135. * @param page
  136. * @param size
  137. * @param type
  138. * @return
  139. */
  140. @RequestMapping(value="/standard/{type}/{favoritesId}/{userId}/{category}")
  141. @LoggerManage(description="文章列表standard")
  142. public List<CollectSummary> standard (@RequestParam(value = "page", defaultValue = "0") Integer page,
  143. @RequestParam(value = "size", defaultValue = "15") Integer size, @PathVariable("type") String type,
  144. @PathVariable("favoritesId") Long favoritesId, @PathVariable("userId") Long userId,
  145. @PathVariable("category") String category) {
  146. Sort sort = new Sort(Direction.DESC, "id");
  147. Pageable pageable = PageRequest.of(page, size,sort);
  148. List<CollectSummary> collects = null;
  149. if( "otherpublic".equalsIgnoreCase(type)){
  150. if( null != favoritesId && 0 != favoritesId){
  151. collects = collectService.getCollects(type, userId, pageable, favoritesId,getUserId());
  152. } else{
  153. collects = collectService.getCollects( "others", userId, pageable, null,getUserId());
  154. }
  155. } else if(category != null && ! "".equals(category) && ! "NO".equals(category)){ //用于随便看看功能中收藏列表显示
  156. collects = lookAroundService.queryCollectExplore(pageable,getUserId(),category);
  157. } else if(type != null && ! "".equals(type) && "lookRecord".equals(type)){ //用于浏览记录功能中收藏列表显示
  158. collects =lookRecordService.getLookRecords( this.getUserId(),pageable);
  159. } else{
  160. if( null != favoritesId && 0 != favoritesId){
  161. collects = collectService.getCollects(String.valueOf(favoritesId),getUserId(), pageable, null, null);
  162. } else{
  163. collects=collectService.getCollects(type,getUserId(), pageable, null, null);
  164. }
  165. }
  166. return collects;
  167. }
  168. @RequestMapping(value="/lookAround")
  169. @LoggerManage(description="查看更多lookAround")
  170. public List<CollectSummary> lookAround (@RequestParam(value = "page", defaultValue = "0") Integer page,
  171. @RequestParam(value = "size", defaultValue = "15") Integer size) {
  172. Sort sort = new Sort(Direction.DESC, "id");
  173. Pageable pageable = PageRequest.of(page, size, sort);
  174. List<CollectSummary> collects =lookAroundService.queryCollectExplore(pageable, getUserId(), null);
  175. return collects;
  176. }
  177. /**
  178. * @param page
  179. * @param size
  180. * @param type
  181. * @return
  182. */
  183. @RequestMapping(value="/simple/{type}/{favoritesId}/{userId}/{category}")
  184. @LoggerManage(description="文章列表simple")
  185. public List<CollectSummary> simple (@RequestParam(value = "page", defaultValue = "0") Integer page,
  186. @RequestParam(value = "size", defaultValue = "15") Integer size,@PathVariable("type") String type,
  187. @PathVariable("favoritesId") Long favoritesId,@PathVariable("userId") Long userId
  188. ,@PathVariable("category") String category) {
  189. Sort sort = new Sort(Direction.DESC, "id");
  190. Pageable pageable = PageRequest.of(page, size,sort);
  191. List<CollectSummary> collects = null;
  192. if( "otherpublic".equalsIgnoreCase(type)){
  193. if( null != favoritesId && 0 != favoritesId){
  194. collects = collectService.getCollects(type, userId, pageable, favoritesId,getUserId());
  195. } else{
  196. collects = collectService.getCollects( "others", userId, pageable, null,getUserId());
  197. }
  198. } else if(category != null && ! "".equals(category) && ! "NO".equals(category)){ //用于随便看看功能中收藏列表显示
  199. collects = lookAroundService.queryCollectExplore(pageable,getUserId(),category);
  200. } else{
  201. if( null != favoritesId && 0 != favoritesId){
  202. collects = collectService.getCollects(String.valueOf(favoritesId),getUserId(), pageable, null, null);
  203. } else{
  204. collects = collectService.getCollects(type,getUserId(), pageable, null, null);
  205. }
  206. }
  207. return collects;
  208. }
  209. /**
  210. * @param id
  211. * @param type
  212. */
  213. @RequestMapping(value="/changePrivacy/{id}/{type}")
  214. public Response changePrivacy (@PathVariable("id") long id,@PathVariable("type") CollectType type) {
  215. collectRepository.modifyByIdAndUserId(type, id, getUserId());
  216. return result();
  217. }
  218. /**
  219. * like and unlike
  220. * @param id
  221. * @return
  222. */
  223. @RequestMapping(value="/like/{id}")
  224. @LoggerManage(description="文章点赞或者取消点赞")
  225. public Response like (@PathVariable("id") long id) {
  226. try {
  227. collectService.like(getUserId(), id);
  228. } catch (Exception e) {
  229. // TODO: handle exception
  230. logger.error( "文章点赞或者取消点赞异常:",e);
  231. }
  232. return result();
  233. }
  234. /**
  235. * @param id
  236. * @return
  237. */
  238. @RequestMapping(value="/delete/{id}")
  239. public Response delete (@PathVariable("id") long id) {
  240. Collect collect = collectRepository.findById(id);
  241. if( null != collect && getUserId()==collect.getUserId()){
  242. collectRepository.deleteById(id);
  243. if( null != collect.getFavoritesId() && !IsDelete.YES.equals(collect.getIsDelete())){
  244. favoritesRepository.reduceCountById(collect.getFavoritesId(), DateUtils.getCurrentTime());
  245. }
  246. }
  247. return result();
  248. }
  249. /**
  250. * @param id
  251. * @return
  252. */
  253. @RequestMapping(value="/detail/{id}")
  254. public Collect detail (@PathVariable("id") long id) {
  255. Collect collect=collectRepository.findById(id);
  256. return collect;
  257. }
  258. /**
  259. * 导入收藏夹
  260. *
  261. */
  262. @RequestMapping("/import")
  263. @LoggerManage(description="导入收藏夹操作")
  264. public void importCollect (@RequestParam("htmlFile") MultipartFile htmlFile,String structure,String type){
  265. try {
  266. if(StringUtils.isNotBlank(structure)&& IsDelete.YES.toString().equals(structure)){
  267. // 按照目录结构导入
  268. Map<String, Map<String, String>> map = HtmlUtil.parseHtmlTwo(htmlFile.getInputStream());
  269. if( null == map || map.isEmpty()){
  270. logger.info( "未获取到url连接");
  271. return ;
  272. }
  273. for (Entry<String, Map<String, String>> entry : map.entrySet()) {
  274. String favoritesName = entry.getKey();
  275. Favorites favorites = favoritesRepository.findByUserIdAndName(getUserId(), favoritesName);
  276. if( null == favorites){
  277. favorites = favoritesService.saveFavorites(getUserId(), favoritesName);
  278. }
  279. collectService.importHtml(entry.getValue(), favorites.getId(), getUserId(),type);
  280. }
  281. } else{
  282. Map<String, String> map = HtmlUtil.parseHtmlOne(htmlFile.getInputStream());
  283. if( null == map || map.isEmpty()){
  284. logger.info( "未获取到url连接");
  285. return ;
  286. }
  287. // 全部导入到<导入自浏览器>收藏夹
  288. Favorites favorites = favoritesRepository.findByUserIdAndName(getUserId(), "导入自浏览器");
  289. if( null == favorites){
  290. favorites = favoritesService.saveFavorites(getUserId(), "导入自浏览器");
  291. }
  292. collectService.importHtml(map, favorites.getId(), getUserId(),type);
  293. }
  294. } catch (Exception e) {
  295. logger.error( "导入html异常:",e);
  296. }
  297. }
  298. /**
  299. * 导出收藏夹
  300. * @param favoritesId
  301. * @return
  302. */
  303. @RequestMapping("/export")
  304. @LoggerManage(description="导出收藏夹操作")
  305. public void export (String favoritesId,HttpServletResponse response){
  306. if(StringUtils.isNotBlank(favoritesId)){
  307. try {
  308. String[] ids = favoritesId.split( ",");
  309. String date = new SimpleDateFormat( "yyyyMMddHHmmss").format( new Date());
  310. String fileName= "favorites_" + date + ".html";
  311. StringBuilder sb = new StringBuilder();
  312. for(String id : ids){
  313. try {
  314. sb = sb.append(collectService.exportToHtml(Long.parseLong(id)));
  315. } catch (Exception e) {
  316. logger.error( "异常:",e);
  317. }
  318. }
  319. sb = HtmlUtil.exportHtml( "云收藏夹", sb);
  320. response.setCharacterEncoding( "UTF-8");
  321. response.setHeader( "Content-disposition", "attachment; filename=" + fileName);
  322. response.getWriter().print(sb);
  323. } catch (Exception e) {
  324. logger.error( "异常:",e);
  325. }
  326. }
  327. }
  328. @RequestMapping(value="/searchMy/{key}")
  329. public List<CollectSummary> searchMy (Model model,@RequestParam(value = "page", defaultValue = "0") Integer page,
  330. @RequestParam(value = "size", defaultValue = "20") Integer size, @PathVariable("key") String key) {
  331. Sort sort = new Sort(Direction.DESC, "id");
  332. Pageable pageable = PageRequest.of(page, size,sort);
  333. List<CollectSummary> myCollects=collectService.searchMy(getUserId(),key ,pageable);
  334. model.addAttribute( "myCollects", myCollects);
  335. logger.info( "searchMy end :");
  336. return myCollects;
  337. }
  338. @RequestMapping(value="/searchOther/{key}")
  339. public List<CollectSummary> searchOther (Model model,@RequestParam(value = "page", defaultValue = "0") Integer page,
  340. @RequestParam(value = "size", defaultValue = "20") Integer size, @PathVariable("key") String key) {
  341. Sort sort = new Sort(Direction.DESC, "id");
  342. Pageable pageable = PageRequest.of(page, size,sort);
  343. List<CollectSummary> otherCollects=collectService.searchOther(getUserId(), key, pageable);
  344. logger.info( "searchOther end :");
  345. return otherCollects;
  346. }
  347. /**
  348. * 查询点赞状态及该文章的点赞数量
  349. */
  350. @RequestMapping(value="/getPaiseStatus/{collectId}")
  351. public Map<String,Object> getPraiseStatus (Model model,@PathVariable("collectId") Long collectId){
  352. Map<String,Object> maps = new HashMap<String,Object>();
  353. Praise praise = praiseRepository.findByUserIdAndCollectId(getUserId(), collectId);
  354. Long praiseCount = praiseRepository.countByCollectId(collectId);
  355. maps.put( "status",praise != null ? "praise" : "unpraise");
  356. maps.put( "praiseCount",praiseCount);
  357. return maps;
  358. }
  359. }

  
  1. package com.favorites.web;
  2. import java.util.List;
  3. import javax.annotation.Resource;
  4. import org.apache.commons.lang3.StringUtils;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.PathVariable;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RestController;
  9. import com.favorites.domain.Collect;
  10. import com.favorites.domain.Comment;
  11. import com.favorites.domain.User;
  12. import com.favorites.domain.result.Response;
  13. import com.favorites.repository.CollectRepository;
  14. import com.favorites.repository.CommentRepository;
  15. import com.favorites.repository.UserRepository;
  16. import com.favorites.service.NoticeService;
  17. import com.favorites.utils.DateUtils;
  18. import com.favorites.utils.StringUtil;
  19. @RestController
  20. @RequestMapping("/comment")
  21. public class CommentController extends BaseController{
  22. @Autowired
  23. private CommentRepository CommentRepository;
  24. @Autowired
  25. private UserRepository userRepository;
  26. @Resource
  27. private NoticeService noticeService;
  28. @Autowired
  29. private CollectRepository colloectRepository;
  30. /**
  31. * @param comment评论
  32. * @return
  33. */
  34. @RequestMapping(value="/add")
  35. public Response add (Comment comment) {
  36. User user = null;
  37. if (comment.getContent().indexOf( "@") > - 1) {
  38. List<String> atUsers = StringUtil.getAtUser(comment.getContent());
  39. if(atUsers!= null && atUsers.size()> 0){
  40. user = userRepository.findByUserName(atUsers.get( 0));
  41. if ( null != user) {
  42. comment.setReplyUserId(user.getId());
  43. } else {
  44. logger.info( "为找到匹配:" + atUsers.get( 0) + "的用户.");
  45. }
  46. String content=comment.getContent().substring( 0,comment.getContent().indexOf( "@"));
  47. if(StringUtils.isBlank(content)){
  48. content=comment.getContent().substring(comment.getContent().indexOf( "@")+user.getUserName().length()+ 1,comment.getContent().length());
  49. }
  50. comment.setContent(content);
  51. }
  52. }
  53. comment.setUserId(getUserId());
  54. comment.setCreateTime(DateUtils.getCurrentTime());
  55. CommentRepository.save(comment);
  56. if( null != user){
  57. // 保存消息通知(回复)
  58. noticeService.saveNotice(String.valueOf(comment.getCollectId()), "comment", user.getId(), String.valueOf(comment.getId()));
  59. } else{
  60. // 保存消息通知(直接评论)
  61. Collect collect = colloectRepository.findById(( long)comment.getCollectId());
  62. if( null != collect){
  63. noticeService.saveNotice(String.valueOf(comment.getCollectId()), "comment", collect.getUserId(), String.valueOf(comment.getId()));
  64. }
  65. }
  66. return result();
  67. }
  68. /**
  69. * @param collectId
  70. * @return
  71. */
  72. @RequestMapping(value="/list/{collectId}")
  73. public List<Comment> list (@PathVariable("collectId") long collectId) {
  74. List<Comment> comments= CommentRepository.findByCollectIdOrderByIdDesc(collectId);
  75. return convertComment(comments);
  76. }
  77. /**
  78. * @param id
  79. * @return
  80. */
  81. @RequestMapping(value="/delete/{id}")
  82. public Response delete (@PathVariable("id") long id) {
  83. CommentRepository.deleteById(id);
  84. return result();
  85. }
  86. /**
  87. * 转化时间和用户名
  88. * @param comments
  89. * @return
  90. */
  91. private List<Comment> convertComment (List<Comment> comments) {
  92. for (Comment comment : comments) {
  93. User user = userRepository.findById(( long)comment.getUserId());
  94. comment.setCommentTime(DateUtils.getTimeFormatText(comment.getCreateTime()));
  95. comment.setUserName(user.getUserName());
  96. comment.setProfilePicture(user.getProfilePicture());
  97. if(comment.getReplyUserId()!= null && comment.getReplyUserId()!= 0){
  98. User replyUser = userRepository.findById(( long)comment.getReplyUserId());
  99. comment.setReplyUserName(replyUser.getUserName());
  100. }
  101. }
  102. return comments;
  103. }
  104. }

五,项目总结

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


转载:https://blog.csdn.net/whirlwind526/article/details/128602204
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场