0


手把手教你设计一个CSDN系统

在CSDN发一个CSDN系统是什么体验?

大家都知道CSDN 有一个下载的模块,就是用户上传资源然后管理员会进行审核,上传资源的用户可以赚钱还可以赚积分。
在这里插入图片描述
那么个人可不可以开发这样的系统呢?

完全可以!

小孟前面就就可开发了一个,而且处理很详细的教程。具体的介绍如下所示:

一,技术简介

该项目非常详细的讲解了springboot,可以用于面试、毕设、学习等。
最新版的springboot2.0框架;

前端框架采用流行的Layui;

redis高性能缓存框架,存放热门数据,常用数据;

thymeleaf模版引擎;

shiro安全框架;

javamail集成,找回密码用到;

数据库连接池使用的是阿里巴巴的Druid;

全文检索lucene;

QQ第三方登录。
在这里插入图片描述
在这里插入图片描述

二,系统演示

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
系统不管是界面还是功能都非常的nice,如果想看详细的教程或者演示,也有对系统的本系统的学习

https://www.bilibili.com/video/BV1jJ41197BJ?p=110&vd_source=e64f225fc5daf048d2687502cb23bb3b

三,核心代码展示

/**
 * 小孟V:jishulearn
 */@RestController@RequestMapping(value ="/article")publicclassArticleController{@AutowiredprivateArcTypeService arcTypeService;@AutowiredprivateArticleService articleService;@AutowiredprivateArticleIndex articleIndex;/**
     * 按资源类型分页查询资源列表
     * @param type
     * @param currentPage
     * @return
     */@RequestMapping("/{type}/{currentPage}")publicModelAndViewtype(@PathVariable(value ="type",required =false)String type,@PathVariable(value ="currentPage",required =false)Integer currentPage){ModelAndView mav =newModelAndView();
        mav.setViewName("index");//类型的html代码List arcTypleList = arcTypeService.listAll(Sort.Direction.ASC,"sort");
        mav.addObject("arcTypeStr",HTMLUtil.getArcTypeStr(type,arcTypleList));//资源列表Map<String,Object> map = articleService.list(type,currentPage,Consts.PAGE_SIZE);
        mav.addObject("articleList",map.get("data"));//分页html代码
        mav.addObject("pageStr",HTMLUtil.getPagation("/article/"+type,Integer.parseInt(String.valueOf(map.get("count"))),currentPage,"该分类还没有数据..."));return mav;}/**
     * 关键字分词搜索
     */@RequestMapping("/search")publicModelAndViewsearch(String keywords,@RequestParam(value ="page",required =false)Integer page)throwsParseException,InvalidTokenOffsetsException,org.apache.lucene.queryparser.classic.ParseException,IOException{if(page==null){
            page =1;}ModelAndView mav =newModelAndView();
        mav.setViewName("index");//类型的html代码List arcTypleList = arcTypeService.listAll(Sort.Direction.ASC,"sort");
        mav.addObject("arcTypeStr",HTMLUtil.getArcTypeStr("all",arcTypleList));//资源列表List<Article> articleList = articleIndex.search(keywords);Integer toIndex = articleList.size()>=page*Consts.PAGE_SIZE?page*Consts.PAGE_SIZE:articleList.size();
        mav.addObject("articleList",articleList.subList((page-1)*Consts.PAGE_SIZE,toIndex));
        mav.addObject("keywords",keywords);//分页html代码int totalPage = articleList.size()%Consts.PAGE_SIZE==0?articleList.size()/Consts.PAGE_SIZE:articleList.size()/Consts.PAGE_SIZE+1;String targetUrl ="/article/search?keywords="+keywords;String msg ="没有关键字是 \"<font style=\"border: 0px;color:red;font-weight:bold;padding-left: 3px; padding-right: 3px;\" >"+keywords +"</font>\" 的相关资源,请联系站长!";
        mav.addObject("pageStr",HTMLUtil.getPagation2(targetUrl,totalPage,page,msg));return mav;}/**
     * 资源详情
     */@RequestMapping("/detail/{articleId}")publicModelAndViewdetail(@PathVariable(value ="articleId",required =false)String articleId)throwsIOException,org.apache.lucene.queryparser.classic.ParseException{ModelAndView mav =newModelAndView();String replace = articleId.replace(".html","");
        articleService.updateClick(Integer.parseInt(replace));Article article = articleService.getById(Integer.parseInt(replace));if(article.getState()!=2){returnnull;}
        mav.addObject("article",article);//类型的html代码List arcTypleList = arcTypeService.listAll(Sort.Direction.ASC,"sort");
        mav.addObject("arcTypeStr",HTMLUtil.getArcTypeStr(article.getArcType().getArcTypeId().toString(),arcTypleList));//通过lucene分词查找相似资源List<Article> articleList = articleIndex.searchNoHighLighter(article.getName().replace("视频","").replace("教程","").replace("下载","").replace("PDF",""));if(articleList!=null&&articleList.size()>0){
            mav.addObject("similarityArticleList",articleList);}
        mav.setViewName("detail");return mav;}/**
     * 判断资源是否免费
     */@ResponseBody@RequestMapping("/isFree")publicbooleanisFree(Integer articleId){Article article = articleService.getById(articleId);return article.isFree();}}
/**
 * 小孟V:jishulearn
 */@Controller@RequestMapping(value ="/comment")publicclassCommentController{@AutowiredprivateCommentService commentService;/**
     * 前端提交保存评论信息
     * @param comment
     * @param session
     * @return
     */@ResponseBody@PostMapping("/add")publicMap<String,Object>add(Comment comment,HttpSession session){Map<String,Object> map =newHashMap<>();
        comment.setContent(StringUtil.esc(comment.getContent()));
        comment.setCommentDate(newDate());
        comment.setState(0);
        comment.setUser((User)session.getAttribute(Consts.CURRENT_USER));
        commentService.save(comment);
        map.put("success",true);return map;}/**
     * 分页查询某个资源的评论信息
     */@ResponseBody@RequestMapping(value ="/list")publicMap<String,Object>list(Comment s_comment,@RequestParam(value ="page",required =false)Integer page){
        s_comment.setState(1);Page<Comment> commentPage = commentService.list(s_comment,page,5,Sort.Direction.DESC,"commentDate");Map<String,Object> map =newHashMap<>();
        map.put("data",HTMLUtil.getCommentPageStr(commentPage.getContent()));//评论的HTML代码
        map.put("total",commentPage.getTotalPages());//总页数return map;}}
/**
 * 根路径及其他请求处理
 */@ControllerpublicclassIndexController{@AutowiredprivateArcTypeService arcTypeService;@AutowiredprivateArticleService articleService;@AutowiredprivateUserService userService;@AutowiredprivateMessageService messageService;@Value("${imgFilePath}")privateString imgFilePath;//图片上传路径/**
     * 首页
     */@RequestMapping("/")publicModelAndViewindex(){ModelAndView mav =newModelAndView();
        mav.setViewName("index");//类型的html代码List arcTypleList = arcTypeService.listAll(Sort.Direction.ASC,"sort");
        mav.addObject("arcTypeStr",HTMLUtil.getArcTypeStr("all",arcTypleList));//资源列表Map<String,Object> map = articleService.list("all",1,Consts.PAGE_SIZE);
        mav.addObject("articleList",map.get("data"));//分页html代码
        mav.addObject("pageStr",HTMLUtil.getPagation("/article/all",Integer.parseInt(String.valueOf(map.get("count"))),1,"该分类还没有数据..."));return mav;}/**
     * QQ登录回调
     */@RequestMapping("/connect")publicStringqqCallback(HttpServletRequest request,HttpServletResponse response,HttpSession session)throwsQQConnectException{
        response.setContentType("text/html;charset=utf-8");AccessToken accessTokenObj =newOauth().getAccessTokenByRequest(request);String accessToken =null;String openId =null;String state = request.getParameter("state");String session_state =(String) session.getAttribute("qq_connect_state");if(StringUtil.isEmpty(session_state)||!session_state.equals(state)){System.out.println("非法请求");return"redirect:/";}
        accessToken = accessTokenObj.getAccessToken();if(StringUtil.isEmpty(accessToken)){System.out.println("没有获取到响应参数");return"redirect:/";}
        session.setAttribute("accessToken",accessToken);OpenID openIDObj =newOpenID(accessToken);
        openId = openIDObj.getUserOpenID();UserInfo qzoneUserInfo =newUserInfo(accessToken,openId);UserInfoBean userInfoBean = qzoneUserInfo.getUserInfo();if(userInfoBean==null||userInfoBean.getRet()!=0||StringUtil.isNotEmpty(userInfoBean.getMsg())){System.out.println("没有对应的qq信息");return"redirect:/";}//获取用户成功User currentUser =(User)session.getAttribute(Consts.CURRENT_USER);if(currentUser!=null&&StringUtil.isNotEmpty(currentUser.getUserName())&&StringUtil.isNotEmpty(currentUser.getEmail())&&StringUtil.isEmpty(currentUser.getOpenId())){
            currentUser.setOpenId(openId);
            userService.save(currentUser);
            session.setAttribute(Consts.CURRENT_USER,currentUser);return"redirect:/";}User user = userService.findByOpenId(openId);if(user==null){//该用户是第一次登录,先注册
            user =newUser();
            user.setOpenId(openId);
            user.setNickname(userInfoBean.getNickname());String imgName =DateUtil.getCurrentDateStr()+".jpg";downloadPicture(userInfoBean.getAvatar().getAvatarURL100(),imgFilePath+imgName);
            user.setHeadPortrait(imgName);
            user.setSex(userInfoBean.getGender());
            user.setPassword(CryptographyUtil.md5("123456",CryptographyUtil.SALT));
            user.setRegistrationDate(newDate());
            user.setLatelyLoginTime(newDate());//userService.save(user);
            session.setAttribute(Consts.CURRENT_USER,user);}else{//已经注册过,更新用户信息,直接将信息存入session 然后跳转if(!user.isOff()){//非封号状态
                user.setNickname(userInfoBean.getNickname());
                user.setSex(userInfoBean.getGender());
                user.setLatelyLoginTime(newDate());
                userService.save(user);Subject subject =SecurityUtils.getSubject();UsernamePasswordToken token =newUsernamePasswordToken(user.getUserName(),user.getPassword());
                subject.login(token);//登录验证Integer messageCount = messageService.getCountByUserId(user.getUserId());
                user.setMessageCount(messageCount);Article s_article =newArticle();
                s_article.setUseful(false);
                s_article.setUser(user);
                session.setAttribute(Consts.UN_USEFUL_ARTICLE_COUNT,articleService.getCount(s_article,null,null,null));
                session.setAttribute(Consts.CURRENT_USER,user);}}return"redirect:/";}/**
     * 通过链接下载图片保存到头像文件夹
     */privatevoiddownloadPicture(String urlString,String path){URL url =null;DataInputStream dataInputStream =null;FileOutputStream fileOutputStream =null;try{
            url =newURL(urlString);
            dataInputStream =newDataInputStream(url.openStream());
            fileOutputStream =newFileOutputStream(newFile(path));ByteArrayOutputStream output =newByteArrayOutputStream();byte[] buffer =newbyte[1024];int length;while((length = dataInputStream.read(buffer))>0){
                output.write(buffer,0,length);}
            fileOutputStream.write(output.toByteArray());}catch(Exception e){
            e.printStackTrace();}finally{try{
                dataInputStream.close();
                fileOutputStream.close();}catch(Exception e){
                e.printStackTrace();}}}

我是小孟,欢迎关注我!可以一起交流。点赞评论是对我最大支持!

标签: java lucene spring boot

本文转载自: https://blog.csdn.net/mengchuan6666/article/details/125365933
版权归原作者 程序员springmeng 所有, 如有侵权,请联系我们删除。

“手把手教你设计一个CSDN系统”的评论:

还没有评论