diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index 817acb6e..ebaf883b --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ !.mvn/wrapper/maven-wrapper.jar -target/ + ### STS ### .apt_generated .classpath @@ -13,6 +13,8 @@ target/ *.iws *.iml *.ipr +*.log +*.gz ### NetBeans ### nbproject/private/ @@ -22,5 +24,12 @@ dist/ nbdist/ .nb-gradle/ -#Mac -.DS_Store \ No newline at end of file + +.DS_Store + +target/ +.mvn/ +mvnw.cmd +mvnw +sens-log/ +/templates \ No newline at end of file diff --git a/ForestBlog/pom.xml b/ForestBlog/pom.xml index 19337842..aa830ec6 100755 --- a/ForestBlog/pom.xml +++ b/ForestBlog/pom.xml @@ -7,6 +7,17 @@ 1.0.0-SNAPSHOT ForestBlog Maven Webapp http://maven.apache.org + + + + 1.8 + 1.8 + UTF-8 + 4.3.19.RELEASE + 2.10.1 + + + @@ -44,63 +55,63 @@ org.springframework spring-core - 4.2.0.RELEASE + ${spring.version} org.springframework spring-beans - 4.2.0.RELEASE + ${spring.version} org.springframework spring-context - 4.2.0.RELEASE + ${spring.version} org.springframework spring-context-support - 4.2.0.RELEASE + ${spring.version} org.springframework spring-web - 4.2.0.RELEASE + ${spring.version} org.springframework spring-test - 4.2.0.RELEASE + ${spring.version} org.springframework spring-webmvc - 4.2.0.RELEASE + ${spring.version} org.springframework spring-tx - 4.2.0.RELEASE + ${spring.version} org.springframework spring-jdbc - 4.2.0.RELEASE + ${spring.version} org.springframework spring-aop - 4.2.0.RELEASE + ${spring.version} org.springframework spring-aspects - 4.2.0.RELEASE + ${spring.version} @@ -117,7 +128,7 @@ mysql mysql-connector-java - 5.1.30 + 8.0.11 @@ -125,23 +136,23 @@ druid 1.0.16 - + - log4j - log4j - 1.2.17 + ch.qos.logback + logback-classic + 1.1.2 - org.slf4j - slf4j-api - 1.7.21 + ch.qos.logback + logback-core + 1.1.2 - - commons-logging - commons-logging - 1.2 + org.logback-extensions + logback-ext-spring + 0.1.1 + junit @@ -154,7 +165,7 @@ commons-fileupload commons-fileupload - 1.2.2 + 1.3.3 commons-io @@ -196,7 +207,6 @@ 26.0-jre - com.github.pagehelper pagehelper @@ -205,7 +215,7 @@ com.alibaba fastjson - 1.2.47 + 1.2.72 @@ -215,13 +225,23 @@ 4.1.13 - + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind-version} + + + com.fasterxml.jackson.core + jackson-core + ${jackson-databind-version} + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson-databind-version} + - - 1.8 - 1.8 - UTF-8 - + diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/AdminController.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/AdminController.java index 560b30a8..90882f82 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/AdminController.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/AdminController.java @@ -1,8 +1,10 @@ package com.liuyanzhao.ssm.blog.controller.admin; +import com.liuyanzhao.ssm.blog.dto.JsonResult; import com.liuyanzhao.ssm.blog.entity.Article; import com.liuyanzhao.ssm.blog.entity.Comment; import com.liuyanzhao.ssm.blog.entity.User; +import com.liuyanzhao.ssm.blog.enums.UserRole; import com.liuyanzhao.ssm.blog.service.ArticleService; import com.liuyanzhao.ssm.blog.service.CommentService; import com.liuyanzhao.ssm.blog.service.UserService; @@ -10,9 +12,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; @@ -45,13 +49,20 @@ public class AdminController { * @return */ @RequestMapping("/admin") - public String index(Model model) { + public String index(Model model, HttpSession session) { + User user = (User) session.getAttribute("user"); + Integer userId = null; + if (!UserRole.ADMIN.getValue().equals(user.getUserRole())) { + // 用户查询自己的文章, 管理员查询所有的 + userId = user.getUserId(); + } //文章列表 - List
articleList = articleService.listRecentArticle(5); - model.addAttribute("articleList",articleList); + List
articleList = articleService.listRecentArticle(userId, 5); + model.addAttribute("articleList", articleList); + //评论列表 - List commentList = commentService.listRecentComment(5); - model.addAttribute("commentList",commentList); + List commentList = commentService.listRecentComment(userId, 5); + model.addAttribute("commentList", commentList); return "Admin/index"; } @@ -61,10 +72,22 @@ public String index(Model model) { * @return */ @RequestMapping("/login") - public String loginPage() { + public String + loginPage() { return "Admin/login"; } + + /** + * 登录页面显示 + * + * @return + */ + @RequestMapping("/register") + public String registerPage() { + return "Admin/register"; + } + /** * 登录验证 * @@ -72,29 +95,32 @@ public String loginPage() { * @param response * @return */ - @RequestMapping(value = "/loginVerify",method = RequestMethod.POST) + @RequestMapping(value = "/loginVerify", method = RequestMethod.POST, produces = {"text/plain;charset=UTF-8"}) @ResponseBody - public String loginVerify(HttpServletRequest request, HttpServletResponse response) { + public String loginVerify(HttpServletRequest request, HttpServletResponse response) { Map map = new HashMap(); String username = request.getParameter("username"); String password = request.getParameter("password"); String rememberme = request.getParameter("rememberme"); User user = userService.getUserByNameOrEmail(username); - if(user==null) { - map.put("code",0); - map.put("msg","用户名无效!"); - } else if(!user.getUserPass().equals(password)) { - map.put("code",0); - map.put("msg","密码错误!"); + if (user == null) { + map.put("code", 0); + map.put("msg", "用户名无效!"); + } else if (!user.getUserPass().equals(password)) { + map.put("code", 0); + map.put("msg", "密码错误!"); + } else if (user.getUserStatus() == 0) { + map.put("code", 0); + map.put("msg", "账号已禁用!"); } else { //登录成功 - map.put("code",1); - map.put("msg",""); + map.put("code", 1); + map.put("msg", ""); //添加session request.getSession().setAttribute("user", user); //添加cookie - if(rememberme!=null) { + if (rememberme != null) { //创建两个Cookie对象 Cookie nameCookie = new Cookie("username", username); //设置Cookie的有效期为3天 @@ -113,6 +139,47 @@ public String loginVerify(HttpServletRequest request, HttpServletResponse respon return result; } + /** + * 登录验证 + * + * @param request + * @return + */ + @RequestMapping(value = "/registerSubmit", method = RequestMethod.POST) + @ResponseBody + public JsonResult registerSubmit(HttpServletRequest request) { + String username = request.getParameter("username"); + String nickname = request.getParameter("nickname"); + String email = request.getParameter("email"); + String password = request.getParameter("password"); + User checkUserName = userService.getUserByName(username); + if (checkUserName != null) { + return new JsonResult().fail("用户名已存在"); + } + User checkEmail = userService.getUserByEmail(username); + if (checkEmail != null) { + return new JsonResult().fail("电子邮箱已存在"); + } + + // 添加用户 + User user = new User(); + user.setUserAvatar("/img/avatar/avatar.png"); + user.setUserName(username); + user.setUserNickname(nickname); + user.setUserPass(password); + user.setUserEmail(email); + user.setUserStatus(1); + user.setArticleCount(0); + user.setUserRole(UserRole.USER.getValue()); + try { + userService.insertUser(user); + } catch (Exception e) { + e.printStackTrace(); + return new JsonResult().fail("系统异常"); + } + return new JsonResult().ok("注册成功"); + } + /** * 退出登录 * @@ -120,11 +187,62 @@ public String loginVerify(HttpServletRequest request, HttpServletResponse respon * @return */ @RequestMapping(value = "/admin/logout") - public String logout(HttpSession session) { + public String logout(HttpSession session) { session.removeAttribute("user"); session.invalidate(); return "redirect:/login"; } + /** + * 基本信息页面显示 + * + * @return + */ + @RequestMapping(value = "/admin/profile") + public ModelAndView userProfileView(HttpSession session) { + + ModelAndView modelAndView = new ModelAndView(); + User sessionUser = (User) session.getAttribute("user"); + User user = userService.getUserById(sessionUser.getUserId()); + modelAndView.addObject("user", user); + + modelAndView.setViewName("Admin/User/profile"); + return modelAndView; + } + + /** + * 编辑个人信息页面显示 + * + * @param session + * @return + */ + @RequestMapping(value = "/admin/profile/edit") + public ModelAndView editUserView(HttpSession session) { + ModelAndView modelAndView = new ModelAndView(); + User loginUser = (User) session.getAttribute("user"); + User user = userService.getUserById(loginUser.getUserId()); + modelAndView.addObject("user", user); + + modelAndView.setViewName("Admin/User/editProfile"); + return modelAndView; + } + + + /** + * 编辑用户提交 + * + * @param user + * @return + */ + @RequestMapping(value = "/admin/profile/save", method = RequestMethod.POST) + public String saveProfile(User user, HttpSession session) { + User dbUser = (User) session.getAttribute("user"); + + user.setUserId(dbUser.getUserId()); + userService.updateUser(user); + return "redirect:/admin/profile"; + } + + } diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/BackArticleController.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/BackArticleController.java index 86941d64..55d82cca 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/BackArticleController.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/BackArticleController.java @@ -3,7 +3,9 @@ import cn.hutool.http.HtmlUtil; import com.github.pagehelper.PageInfo; import com.liuyanzhao.ssm.blog.dto.ArticleParam; +import com.liuyanzhao.ssm.blog.dto.JsonResult; import com.liuyanzhao.ssm.blog.entity.Article; +import com.liuyanzhao.ssm.blog.enums.UserRole; import com.liuyanzhao.ssm.blog.service.ArticleService; import com.liuyanzhao.ssm.blog.service.CategoryService; import com.liuyanzhao.ssm.blog.service.TagService; @@ -14,16 +16,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpSession; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Objects; /** @@ -49,7 +49,8 @@ public class BackArticleController { @RequestMapping(value = "") public String index(@RequestParam(required = false, defaultValue = "1") Integer pageIndex, @RequestParam(required = false, defaultValue = "10") Integer pageSize, - @RequestParam(required = false) String status, Model model) { + @RequestParam(required = false) String status, Model model, + HttpSession session) { HashMap criteria = new HashMap<>(1); if (status == null) { model.addAttribute("pageUrlPrefix", "/admin/article?pageIndex"); @@ -57,6 +58,12 @@ public String index(@RequestParam(required = false, defaultValue = "1") Integer criteria.put("status", status); model.addAttribute("pageUrlPrefix", "/admin/article?status=" + status + "&pageIndex"); } + + User user = (User) session.getAttribute("user"); + if (!UserRole.ADMIN.getValue().equals(user.getUserRole())) { + // 用户查询自己的文章, 管理员查询所有的 + criteria.put("userId", user.getUserId()); + } PageInfo
articlePageInfo = articleService.pageArticle(pageIndex, pageSize, criteria); model.addAttribute("pageInfo", articlePageInfo); return "Admin/Article/index"; @@ -101,6 +108,7 @@ public String insertArticleSubmit(HttpSession session, ArticleParam articleParam } else { article.setArticleSummary(summaryText); } + article.setArticleThumbnail(articleParam.getArticleThumbnail()); article.setArticleContent(articleParam.getArticleContent()); article.setArticleStatus(articleParam.getArticleStatus()); //填充分类 @@ -132,8 +140,17 @@ public String insertArticleSubmit(HttpSession session, ArticleParam articleParam * * @param id 文章ID */ - @RequestMapping(value = "/delete/{id}") - public void deleteArticle(@PathVariable("id") Integer id) { + @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST) + public void deleteArticle(@PathVariable("id") Integer id, HttpSession session) { + Article dbArticle = articleService.getArticleByStatusAndId(null, id); + if (dbArticle == null) { + return; + } + User user = (User) session.getAttribute("user"); + // 如果不是管理员,访问其他用户的数据,则跳转403 + if (!Objects.equals(dbArticle.getArticleUserId(), user.getUserId()) && !Objects.equals(user.getUserRole(), UserRole.ADMIN.getValue())) { + return; + } articleService.deleteArticle(id); } @@ -145,22 +162,27 @@ public void deleteArticle(@PathVariable("id") Integer id) { * @return */ @RequestMapping(value = "/edit/{id}") - public ModelAndView editArticleView(@PathVariable("id") Integer id) { - ModelAndView modelAndView = new ModelAndView(); + public String editArticleView(@PathVariable("id") Integer id, Model model, HttpSession session) { Article article = articleService.getArticleByStatusAndId(null, id); - modelAndView.addObject("article", article); + if (article == null) { + return "redirect:/404"; + } + User user = (User) session.getAttribute("user"); + // 如果不是管理员,访问其他用户的数据,则跳转403 + if (!Objects.equals(article.getArticleUserId(), user.getUserId()) && !Objects.equals(user.getUserRole(), UserRole.ADMIN.getValue())) { + return "redirect:/403"; + } + model.addAttribute("article", article); List categoryList = categoryService.listCategory(); - modelAndView.addObject("categoryList", categoryList); + model.addAttribute("categoryList", categoryList); List tagList = tagService.listTag(); - modelAndView.addObject("tagList", tagList); - + model.addAttribute("tagList", tagList); - modelAndView.setViewName("Admin/Article/edit"); - return modelAndView; + return "Admin/Article/edit"; } @@ -171,8 +193,18 @@ public ModelAndView editArticleView(@PathVariable("id") Integer id) { * @return */ @RequestMapping(value = "/editSubmit", method = RequestMethod.POST) - public String editArticleSubmit(ArticleParam articleParam) { + public String editArticleSubmit(ArticleParam articleParam, HttpSession session) { + Article dbArticle = articleService.getArticleByStatusAndId(null, articleParam.getArticleId()); + if (dbArticle == null) { + return "redirect:/404"; + } + User user = (User) session.getAttribute("user"); + // 如果不是管理员,访问其他用户的数据,则跳转403 + if (!Objects.equals(dbArticle.getArticleUserId(), user.getUserId()) && !Objects.equals(user.getUserRole(), UserRole.ADMIN.getValue())) { + return "redirect:/403"; + } Article article = new Article(); + article.setArticleThumbnail(articleParam.getArticleThumbnail()); article.setArticleId(articleParam.getArticleId()); article.setArticleTitle(articleParam.getArticleTitle()); article.setArticleContent(articleParam.getArticleContent()); @@ -208,6 +240,55 @@ public String editArticleSubmit(ArticleParam articleParam) { return "redirect:/admin/article"; } + /** + * 后台添加文章提交操作 + * + * @param articleParam + * @return + */ + @RequestMapping(value = "/insertDraftSubmit", method = RequestMethod.POST) + public String insertDraftSubmit(HttpSession session, ArticleParam articleParam) { + Article article = new Article(); + //用户ID + User user = (User) session.getAttribute("user"); + if (user != null) { + article.setArticleUserId(user.getUserId()); + } + article.setArticleTitle(articleParam.getArticleTitle()); + //文章摘要 + int summaryLength = 150; + String summaryText = HtmlUtil.cleanHtmlTag(articleParam.getArticleContent()); + if (summaryText.length() > summaryLength) { + String summary = summaryText.substring(0, summaryLength); + article.setArticleSummary(summary); + } else { + article.setArticleSummary(summaryText); + } + article.setArticleThumbnail(articleParam.getArticleThumbnail()); + article.setArticleContent(articleParam.getArticleContent()); + article.setArticleStatus(articleParam.getArticleStatus()); + //填充分类 + List categoryList = new ArrayList<>(); + if (articleParam.getArticleChildCategoryId() != null) { + categoryList.add(new Category(articleParam.getArticleParentCategoryId())); + } + if (articleParam.getArticleChildCategoryId() != null) { + categoryList.add(new Category(articleParam.getArticleChildCategoryId())); + } + article.setCategoryList(categoryList); + //填充标签 + List tagList = new ArrayList<>(); + if (articleParam.getArticleTagIds() != null) { + for (int i = 0; i < articleParam.getArticleTagIds().size(); i++) { + Tag tag = new Tag(articleParam.getArticleTagIds().get(i)); + tagList.add(tag); + } + } + article.setTagList(tagList); + + articleService.insertArticle(article); + return "redirect:/admin"; + } } diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/BackCommentController.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/BackCommentController.java index b0a05111..ebf5e59a 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/BackCommentController.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/BackCommentController.java @@ -1,10 +1,15 @@ package com.liuyanzhao.ssm.blog.controller.admin; +import cn.hutool.http.HtmlUtil; import com.github.pagehelper.PageInfo; +import com.liuyanzhao.ssm.blog.dto.JsonResult; import com.liuyanzhao.ssm.blog.entity.Article; import com.liuyanzhao.ssm.blog.entity.Comment; +import com.liuyanzhao.ssm.blog.entity.User; import com.liuyanzhao.ssm.blog.enums.ArticleStatus; +import com.liuyanzhao.ssm.blog.enums.Role; +import com.liuyanzhao.ssm.blog.enums.UserRole; import com.liuyanzhao.ssm.blog.util.MyUtils; import com.liuyanzhao.ssm.blog.service.ArticleService; import com.liuyanzhao.ssm.blog.service.CommentService; @@ -14,8 +19,8 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; -import java.util.Date; -import java.util.List; +import javax.servlet.http.HttpSession; +import java.util.*; /** @@ -33,18 +38,47 @@ public class BackCommentController { /** * 评论页面 + * 我发送的评论 * * @param pageIndex 页码 * @param pageSize 页大小 * @return modelAndView */ @RequestMapping(value = "") - public String commentListView(@RequestParam(required = false, defaultValue = "1") Integer pageIndex, - @RequestParam(required = false, defaultValue = "10") Integer pageSize, - Model model) { - PageInfo commentPageInfo = commentService.listCommentByPage(pageIndex, pageSize); + public String commentList(@RequestParam(required = false, defaultValue = "1") Integer pageIndex, + @RequestParam(required = false, defaultValue = "10") Integer pageSize, + HttpSession session, + Model model) { + User user = (User) session.getAttribute("user"); + HashMap criteria = new HashMap<>(); + if (!UserRole.ADMIN.getValue().equals(user.getUserRole())) { + // 用户查询自己的文章, 管理员查询所有的 + criteria.put("userId", user.getUserId()); + } + PageInfo commentPageInfo = commentService.listCommentByPage(pageIndex, pageSize, criteria); + model.addAttribute("pageInfo", commentPageInfo); + model.addAttribute("pageUrlPrefix", "/admin/comment?pageIndex"); + return "Admin/Comment/index"; + } + + + /** + * 评论页面 + * 我收到的评论 + * + * @param pageIndex 页码 + * @param pageSize 页大小 + * @return modelAndView + */ + @RequestMapping(value = "/receive") + public String myReceiveComment(@RequestParam(required = false, defaultValue = "1") Integer pageIndex, + @RequestParam(required = false, defaultValue = "10") Integer pageSize, + HttpSession session, + Model model) { + User user = (User) session.getAttribute("user"); + PageInfo commentPageInfo = commentService.listReceiveCommentByPage(pageIndex, pageSize, user.getUserId()); model.addAttribute("pageInfo", commentPageInfo); - model.addAttribute("pageUrlPrefix","/admin/comment?pageIndex"); + model.addAttribute("pageUrlPrefix", "/admin/comment?pageIndex"); return "Admin/Comment/index"; } @@ -55,15 +89,21 @@ public String commentListView(@RequestParam(required = false, defaultValue = "1" * @param request * @param comment */ - @RequestMapping(value = "/insert", method = {RequestMethod.POST}) + @RequestMapping(value = "/insert", method = {RequestMethod.POST}, produces = {"text/plain;charset=UTF-8"}) @ResponseBody - public void insertComment(HttpServletRequest request, Comment comment) { + public void insertComment(HttpServletRequest request, Comment comment, HttpSession session) { + User user = (User) session.getAttribute("user"); + Article article = articleService.getArticleByStatusAndId(null, comment.getCommentArticleId()); + if (article == null) { + return; + } + //添加评论 + comment.setCommentUserId(user.getUserId()); comment.setCommentIp(MyUtils.getIpAddr(request)); comment.setCommentCreateTime(new Date()); commentService.insertComment(comment); //更新文章的评论数 - Article article = articleService.getArticleByStatusAndId(null, comment.getCommentArticleId()); articleService.updateCommentCount(article.getArticleId()); } @@ -73,8 +113,13 @@ public void insertComment(HttpServletRequest request, Comment comment) { * @param id 批量ID */ @RequestMapping(value = "/delete/{id}") - public void deleteComment(@PathVariable("id") Integer id) { + public void deleteComment(@PathVariable("id") Integer id, HttpSession session) { Comment comment = commentService.getCommentById(id); + User user = (User) session.getAttribute("user"); + // 如果不是管理员,访问其他用户的数据,没有权限 + if (!Objects.equals(user.getUserRole(), UserRole.ADMIN.getValue()) && !Objects.equals(comment.getCommentUserId(), user.getUserId())) { + return; + } //删除评论 commentService.deleteComment(id); //删除其子评论 @@ -94,7 +139,12 @@ public void deleteComment(@PathVariable("id") Integer id) { * @return */ @RequestMapping(value = "/edit/{id}") - public String editCommentView(@PathVariable("id") Integer id, Model model) { + public String editCommentView(@PathVariable("id") Integer id, Model model, HttpSession session) { + // 没有权限操作,只有管理员可以操作 + User user = (User) session.getAttribute("user"); + if (!Objects.equals(user.getUserRole(), UserRole.ADMIN.getValue())) { + return "redirect:/403"; + } Comment comment = commentService.getCommentById(id); model.addAttribute("comment", comment); return "Admin/Comment/edit"; @@ -108,7 +158,12 @@ public String editCommentView(@PathVariable("id") Integer id, Model model) { * @return */ @RequestMapping(value = "/editSubmit", method = RequestMethod.POST) - public String editCommentSubmit(Comment comment) { + public String editCommentSubmit(Comment comment, HttpSession session) { + User user = (User) session.getAttribute("user"); + // 没有权限操作,只有管理员可以操作 + if (!Objects.equals(user.getUserRole(), UserRole.ADMIN.getValue())) { + return "redirect:/403"; + } commentService.updateComment(comment); return "redirect:/admin/comment"; } @@ -135,14 +190,27 @@ public String replyCommentView(@PathVariable("id") Integer id, Model model) { * @return */ @RequestMapping(value = "/replySubmit", method = RequestMethod.POST) - public String replyCommentSubmit(HttpServletRequest request, Comment comment) { + public String replyCommentSubmit(HttpServletRequest request, Comment comment, HttpSession session) { //文章评论数+1 Article article = articleService.getArticleByStatusAndId(ArticleStatus.PUBLISH.getValue(), comment.getCommentArticleId()); + if (article == null) { + return "redirect:/404"; + } + User user = (User) session.getAttribute("user"); + comment.setCommentContent(HtmlUtil.escape(comment.getCommentContent())); + comment.setCommentAuthorName(user.getUserNickname()); + comment.setCommentAuthorEmail(user.getUserEmail()); + comment.setCommentAuthorUrl(user.getUserUrl()); article.setArticleCommentCount(article.getArticleCommentCount() + 1); articleService.updateArticle(article); //添加评论 comment.setCommentCreateTime(new Date()); comment.setCommentIp(MyUtils.getIpAddr(request)); + if (Objects.equals(user.getUserId(), article.getArticleUserId())) { + comment.setCommentRole(Role.OWNER.getValue()); + } else { + comment.setCommentRole(Role.VISITOR.getValue()); + } commentService.insertComment(comment); return "redirect:/admin/comment"; } diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/BackUserController.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/BackUserController.java index cb35ec6e..852b438a 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/BackUserController.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/BackUserController.java @@ -2,6 +2,7 @@ import com.liuyanzhao.ssm.blog.entity.User; +import com.liuyanzhao.ssm.blog.enums.UserRole; import com.liuyanzhao.ssm.blog.service.UserService; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; @@ -33,11 +34,11 @@ public class BackUserController { * @return */ @RequestMapping(value = "") - public ModelAndView userList() { + public ModelAndView userList() { ModelAndView modelandview = new ModelAndView(); List userList = userService.listUser(); - modelandview.addObject("userList",userList); + modelandview.addObject("userList", userList); modelandview.setViewName("Admin/User/index"); return modelandview; @@ -50,7 +51,7 @@ public ModelAndView userList() { * @return */ @RequestMapping(value = "/insert") - public ModelAndView insertUserView() { + public ModelAndView insertUserView() { ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("Admin/User/insert"); return modelAndView; @@ -62,22 +63,22 @@ public ModelAndView insertUserView() { * @param request * @return */ - @RequestMapping(value = "/checkUserName",method = RequestMethod.POST) + @RequestMapping(value = "/checkUserName", method = RequestMethod.POST, produces = {"text/plain;charset=UTF-8"}) @ResponseBody - public String checkUserName(HttpServletRequest request) { + public String checkUserName(HttpServletRequest request) { Map map = new HashMap(); String username = request.getParameter("username"); User user = userService.getUserByName(username); int id = Integer.valueOf(request.getParameter("id")); //用户名已存在,但不是当前用户(编辑用户的时候,不提示) - if(user!=null) { - if(user.getUserId()!=id) { + if (user != null) { + if (user.getUserId() != id) { map.put("code", 1); map.put("msg", "用户名已存在!"); } } else { - map.put("code",0); - map.put("msg",""); + map.put("code", 0); + map.put("msg", ""); } String result = new JSONObject(map).toString(); return result; @@ -89,22 +90,22 @@ public String checkUserName(HttpServletRequest request) { * @param request * @return */ - @RequestMapping(value = "/checkUserEmail",method = RequestMethod.POST) + @RequestMapping(value = "/checkUserEmail", method = RequestMethod.POST, produces = {"text/plain;charset=UTF-8"}) @ResponseBody - public String checkUserEmail(HttpServletRequest request) { + public String checkUserEmail(HttpServletRequest request) { Map map = new HashMap(); String email = request.getParameter("email"); User user = userService.getUserByEmail(email); int id = Integer.valueOf(request.getParameter("id")); //用户名已存在,但不是当前用户(编辑用户的时候,不提示) - if(user!=null) { - if(user.getUserId()!=id) { + if (user != null) { + if (user.getUserId() != id) { map.put("code", 1); map.put("msg", "电子邮箱已存在!"); } } else { - map.put("code",0); - map.put("msg",""); + map.put("code", 0); + map.put("msg", ""); } String result = new JSONObject(map).toString(); return result; @@ -117,13 +118,14 @@ public String checkUserEmail(HttpServletRequest request) { * @param user * @return */ - @RequestMapping(value = "/insertSubmit",method = RequestMethod.POST) - public String insertUserSubmit(User user) { + @RequestMapping(value = "/insertSubmit", method = RequestMethod.POST) + public String insertUserSubmit(User user) { User user2 = userService.getUserByName(user.getUserName()); User user3 = userService.getUserByEmail(user.getUserEmail()); - if(user2==null&&user3==null) { + if (user2 == null && user3 == null) { user.setUserRegisterTime(new Date()); user.setUserStatus(1); + user.setUserRole(UserRole.USER.getValue()); userService.insertUser(user); } return "redirect:/admin/user"; @@ -136,7 +138,7 @@ public String insertUserSubmit(User user) { * @return */ @RequestMapping(value = "/delete/{id}") - public String deleteUser(@PathVariable("id") Integer id) { + public String deleteUser(@PathVariable("id") Integer id) { userService.deleteUser(id); return "redirect:/admin/user"; } @@ -148,11 +150,11 @@ public String deleteUser(@PathVariable("id") Integer id) { * @return */ @RequestMapping(value = "/edit/{id}") - public ModelAndView editUserView(@PathVariable("id") Integer id) { + public ModelAndView editUserView(@PathVariable("id") Integer id) { ModelAndView modelAndView = new ModelAndView(); - User user = userService.getUserById(id); - modelAndView.addObject("user",user); + User user = userService.getUserById(id); + modelAndView.addObject("user", user); modelAndView.setViewName("Admin/User/edit"); return modelAndView; @@ -165,26 +167,10 @@ public ModelAndView editUserView(@PathVariable("id") Integer id) { * @param user * @return */ - @RequestMapping(value = "/editSubmit",method = RequestMethod.POST) - public String editUserSubmit(User user) { + @RequestMapping(value = "/editSubmit", method = RequestMethod.POST) + public String editUserSubmit(User user) { userService.updateUser(user); return "redirect:/admin/user"; } - /** - * 基本信息页面显示 - * - * @return - */ - @RequestMapping(value = "/profile") - public ModelAndView userProfileView(HttpSession session) { - - ModelAndView modelAndView = new ModelAndView(); - User sessionUser = (User) session.getAttribute("user"); - User user = userService.getUserById(sessionUser.getUserId()); - modelAndView.addObject("user",user); - - modelAndView.setViewName("Admin/User/profile"); - return modelAndView; - } } diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/UploadFileController.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/UploadFileController.java index 28d046fa..7431f47f 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/UploadFileController.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/admin/UploadFileController.java @@ -22,7 +22,8 @@ public class UploadFileController { /** * 文件保存目录,物理路径 */ - public final String rootPath = "/Users/liuyanzhao/Documents/uploads"; +// public final String rootPath = "/Users/liuyanzhao/Documents/uploads"; + public final String rootPath = "D:\\uploads"; public final String allowSuffix = ".bmp.jpg.jpeg.png.gif.pdf.doc.zip.rar.gz"; diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/ArticleController.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/ArticleController.java index 1b9c8bbf..38c78fff 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/ArticleController.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/ArticleController.java @@ -104,7 +104,7 @@ public String getArticleDetailPage(@PathVariable("articleId") Integer articleId, * @param id 文章ID * @return 点赞量数量 */ - @RequestMapping(value = "/article/like/{id}", method = {RequestMethod.POST}) + @RequestMapping(value = "/article/like/{id}", method = {RequestMethod.POST}, produces = {"text/plain;charset=UTF-8"}) @ResponseBody public String increaseLikeCount(@PathVariable("id") Integer id) { Article article = articleService.getArticleByStatusAndId(ArticleStatus.PUBLISH.getValue(), id); @@ -120,7 +120,7 @@ public String increaseLikeCount(@PathVariable("id") Integer id) { * @param id 文章ID * @return 访问量数量 */ - @RequestMapping(value = "/article/view/{id}", method = {RequestMethod.POST}) + @RequestMapping(value = "/article/view/{id}", method = {RequestMethod.POST}, produces = {"text/plain;charset=UTF-8"}) @ResponseBody public String increaseViewCount(@PathVariable("id") Integer id) { Article article = articleService.getArticleByStatusAndId(ArticleStatus.PUBLISH.getValue(), id); diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/CategoryController.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/CategoryController.java index 06d598d0..310c361e 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/CategoryController.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/CategoryController.java @@ -75,7 +75,7 @@ public String getArticleListByCategory(@PathVariable("cateId") Integer cateId, //获得热评文章 List
mostCommentArticleList = articleService.listArticleByCommentCount(8); model.addAttribute("mostCommentArticleList", mostCommentArticleList); - model.addAttribute("pageUrlPrefix", "/category/"+pageIndex+"?pageIndex"); + model.addAttribute("pageUrlPrefix", "/category/"+cateId+"?pageIndex"); return "Home/Page/articleListByCategory"; } diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/CommentController.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/CommentController.java index 53cd0b4f..9e76d921 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/CommentController.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/CommentController.java @@ -4,6 +4,7 @@ import com.liuyanzhao.ssm.blog.dto.JsonResult; import com.liuyanzhao.ssm.blog.entity.Article; import com.liuyanzhao.ssm.blog.entity.Comment; +import com.liuyanzhao.ssm.blog.entity.User; import com.liuyanzhao.ssm.blog.enums.ArticleStatus; import com.liuyanzhao.ssm.blog.enums.Role; import com.liuyanzhao.ssm.blog.service.ArticleService; @@ -13,11 +14,12 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; import java.util.Date; +import java.util.Objects; /** * @author 言曌 @@ -34,32 +36,43 @@ public class CommentController { private ArticleService articleService; /** - * '添加评论 + * 添加评论 * * @param request * @param comment */ @RequestMapping(value = "/comment", method = {RequestMethod.POST}) - public JsonResult insertComment(HttpServletRequest request, Comment comment) { + public JsonResult insertComment(HttpServletRequest request, Comment comment, HttpSession session) { + User user = (User) session.getAttribute("user"); + if (user == null) { + return new JsonResult().fail("请先登录"); + } + Article article = articleService.getArticleByStatusAndId(ArticleStatus.PUBLISH.getValue(), comment.getCommentArticleId()); + if (article == null) { + return new JsonResult().fail("文章不存在"); + } + + //添加评论 + comment.setCommentUserId(user.getUserId()); comment.setCommentCreateTime(new Date()); comment.setCommentIp(MyUtils.getIpAddr(request)); - if (request.getSession().getAttribute("user") != null) { - comment.setCommentRole(Role.ADMIN.getValue()); + if (Objects.equals(user.getUserId(), article.getArticleUserId())) { + comment.setCommentRole(Role.OWNER.getValue()); } else { comment.setCommentRole(Role.VISITOR.getValue()); } - comment.setCommentAuthorAvatar(MyUtils.getGravatar(comment.getCommentAuthorEmail())); + comment.setCommentAuthorAvatar(user.getUserAvatar()); //过滤字符,防止XSS攻击 comment.setCommentContent(HtmlUtil.escape(comment.getCommentContent())); - comment.setCommentAuthorName(HtmlUtil.escape(comment.getCommentAuthorName())); - comment.setCommentAuthorEmail(HtmlUtil.escape(comment.getCommentAuthorEmail())); - comment.setCommentAuthorUrl(HtmlUtil.escape(comment.getCommentAuthorUrl())); + + comment.setCommentAuthorName(user.getUserNickname()); + comment.setCommentAuthorEmail(user.getUserEmail()); + comment.setCommentAuthorUrl(user.getUserUrl()); try { commentService.insertComment(comment); //更新文章的评论数 - Article article = articleService.getArticleByStatusAndId(ArticleStatus.PUBLISH.getValue(), comment.getCommentArticleId()); articleService.updateCommentCount(article.getArticleId()); } catch (Exception e) { e.printStackTrace(); diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/IndexController.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/IndexController.java index 474ab333..aec1455c 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/IndexController.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/IndexController.java @@ -62,7 +62,7 @@ public String index(@RequestParam(required = false, defaultValue = "1") Integer List allTagList = tagService.listTag(); model.addAttribute("allTagList", allTagList); //最新评论 - List recentCommentList = commentService.listRecentComment(10); + List recentCommentList = commentService.listRecentComment(null, 10); model.addAttribute("recentCommentList", recentCommentList); model.addAttribute("pageUrlPrefix", "/article?pageIndex"); return "Home/index"; @@ -91,9 +91,9 @@ public String search( List
mostCommentArticleList = articleService.listArticleByCommentCount(8); model.addAttribute("mostCommentArticleList", mostCommentArticleList); //最新评论 - List recentCommentList = commentService.listRecentComment(10); + List recentCommentList = commentService.listRecentComment(null, 10); model.addAttribute("recentCommentList", recentCommentList); - model.addAttribute("pageUrlPrefix", "/search?pageIndex"); + model.addAttribute("pageUrlPrefix", "/search?keywords=" + keywords + "&pageIndex"); return "Home/Page/search"; } @@ -103,6 +103,13 @@ public String NotFound(@RequestParam(required = false) String message, Model mod return "Home/Error/404"; } + + @RequestMapping("/403") + public String Page403(@RequestParam(required = false) String message, Model model) { + model.addAttribute("message", message); + return "Home/Error/403"; + } + @RequestMapping("/500") public String ServerError(@RequestParam(required = false) String message, Model model) { model.addAttribute("message", message); diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/LinkController.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/LinkController.java index d14e35c2..f0f07f0f 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/LinkController.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/LinkController.java @@ -38,7 +38,7 @@ public String applyLinkView(Model model) { } - @RequestMapping(value = "/applyLinkSubmit",method = {RequestMethod.POST}) + @RequestMapping(value = "/applyLinkSubmit",method = {RequestMethod.POST}, produces = {"text/plain;charset=UTF-8"}) @ResponseBody public void applyLinkSubmit(Link link) { link.setLinkStatus(LinkStatus.HIDDEN.getValue()); diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/TagController.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/TagController.java index 43e0c5f0..cfa3c3c4 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/TagController.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/controller/home/TagController.java @@ -64,7 +64,8 @@ public String getArticleListByTag(@PathVariable("tagId") Integer tagId, //获得热评文章 List
mostCommentArticleList = articleService.listArticleByCommentCount(8); model.addAttribute("mostCommentArticleList", mostCommentArticleList); - model.addAttribute("pageUrlPrefix", "/tag?pageIndex"); + model.addAttribute("pageUrlPrefix", "/tag/"+tagId+"?pageIndex"); + return "Home/Page/articleListByTag"; } diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/dto/ArticleParam.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/dto/ArticleParam.java index af19e332..835e09f9 100644 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/dto/ArticleParam.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/dto/ArticleParam.java @@ -25,6 +25,8 @@ public class ArticleParam { private Integer articleStatus; + private String articleThumbnail; + private List articleTagIds; } diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/dto/Response.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/dto/Response.java deleted file mode 100644 index afb761fa..00000000 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/dto/Response.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.liuyanzhao.ssm.blog.dto; - -/** - * @author 言曌 - * @date 2018/9/2 下午8:34 - */ - -public class Response { - - private Boolean success; - - private String message; - - private T data; - - public Response() { - } - - public Response(Boolean success) { - this.success = success; - } - - public Response(Boolean success, String message) { - this.success = success; - this.message = message; - } - - public Response(Boolean success, String message, T data) { - this.success = success; - this.message = message; - this.data = data; - } - - public static Response yes() { - return new Response(true, "操作成功"); - } - - public static Response yes(T data) { - return new Response(true, "操作成功", data); - } - - - public static Response no() { - return new Response(false, "操作失败"); - } - - public static Response no(String message) { - return new Response(false, message); - } - - public Boolean isSuccess() { - return success; - } - - public void setSuccess(Boolean success) { - this.success = success; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public T getData() { - return data; - } - - public void setData(T data) { - this.data = data; - } -} diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/entity/Article.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/entity/Article.java index 4dd53fca..7b852a30 100644 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/entity/Article.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/entity/Article.java @@ -40,6 +40,8 @@ public class Article implements Serializable{ private String articleSummary; + private String articleThumbnail; + private User user; private List tagList; diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/entity/Category.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/entity/Category.java index 6244d429..904f7676 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/entity/Category.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/entity/Category.java @@ -48,6 +48,8 @@ public Category(Integer categoryId, String categoryName) { public Category(Integer categoryId) { this.categoryId = categoryId; } + + public Category() {} /** * 未分类 @@ -59,4 +61,4 @@ public static Category Default() { } -} \ No newline at end of file +} diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/entity/Comment.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/entity/Comment.java index 6f856947..31f17798 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/entity/Comment.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/entity/Comment.java @@ -7,10 +7,11 @@ /** * 文章评论 + * * @author liuyanzhao */ @Data -public class Comment implements Serializable{ +public class Comment implements Serializable { private static final long serialVersionUID = -1038897351672911219L; private Integer commentId; @@ -42,9 +43,13 @@ public class Comment implements Serializable{ */ private Integer commentRole; + /** + * 评论用户ID + */ + private Integer commentUserId; + /** * 非数据库字段 */ private Article article; - } \ No newline at end of file diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/entity/User.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/entity/User.java index 88544a9d..326ef3c4 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/entity/User.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/entity/User.java @@ -33,6 +33,11 @@ public class User implements Serializable{ private Integer userStatus; + /** + * 用户角色:admin/user + */ + private String userRole; + /** * 文章数量(不是数据库字段) */ diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/enums/Role.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/enums/Role.java index d4096a6b..a95b01ff 100644 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/enums/Role.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/enums/Role.java @@ -7,8 +7,8 @@ public enum Role { - ADMIN(1, "博主"), - VISITOR(0, "访客"); + OWNER(1, "博主"), + VISITOR(0, "其他用户"); private Integer value; diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/enums/UserRole.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/enums/UserRole.java new file mode 100644 index 00000000..3de0d5a0 --- /dev/null +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/enums/UserRole.java @@ -0,0 +1,40 @@ +package com.liuyanzhao.ssm.blog.enums; + +/** + * 角色枚举 + * + * @author 言曌 + * @date 2021/2/25 2:31 下午 + */ + +public enum UserRole { + + ADMIN("admin", "管理员"), + + USER("user", "用户"); + + private String value; + + private String message; + + UserRole(String value, String message) { + this.value = value; + this.message = message; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/interceptor/AdminInterceptor.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/interceptor/AdminInterceptor.java new file mode 100755 index 00000000..7c151209 --- /dev/null +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/interceptor/AdminInterceptor.java @@ -0,0 +1,45 @@ +package com.liuyanzhao.ssm.blog.interceptor; + +import com.liuyanzhao.ssm.blog.entity.User; +import com.liuyanzhao.ssm.blog.enums.UserRole; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Objects; + + +/** + * @author liuyanzhao + */ +@Component +public class AdminInterceptor extends HandlerInterceptorAdapter { + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws IOException { + //这里可以根据session的用户来判断角色的权限,根据权限来转发不同的页面 + User user = (User) request.getSession().getAttribute("user"); + if (user == null) { + response.sendRedirect("/login"); + return false; + } + if (!Objects.equals(user.getUserRole(), UserRole.ADMIN.getValue())) { + return false; + } + return true; + } + + @Override + public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) { + + } + + @Override + public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) { + + } +} + diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/interceptor/SecurityInterceptor.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/interceptor/LoginInterceptor.java similarity index 89% rename from ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/interceptor/SecurityInterceptor.java rename to ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/interceptor/LoginInterceptor.java index 6b03d4aa..1201d869 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/interceptor/SecurityInterceptor.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/interceptor/LoginInterceptor.java @@ -1,7 +1,6 @@ package com.liuyanzhao.ssm.blog.interceptor; import org.springframework.stereotype.Component; -import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; @@ -14,7 +13,7 @@ * @author liuyanzhao */ @Component -public class SecurityInterceptor extends HandlerInterceptorAdapter { +public class LoginInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws IOException { @@ -23,6 +22,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons response.sendRedirect("/login"); return false; } + return true; } diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/mapper/ArticleMapper.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/mapper/ArticleMapper.java index ed86da42..c6930dae 100644 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/mapper/ArticleMapper.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/mapper/ArticleMapper.java @@ -23,6 +23,14 @@ public interface ArticleMapper { */ Integer deleteById(Integer articleId); + /** + * 根据用户ID删除 + * + * @param userId 用户ID + * @return 影响函数 + */ + Integer deleteByUserId(Integer userId); + /** * 添加文章 * @@ -49,6 +57,7 @@ public interface ArticleMapper { /** * 文章归档 + * * @return */ List
listAllNotWithContent(); @@ -86,7 +95,7 @@ public interface ArticleMapper { * 根据id查询用户信息 * * @param status 状态 - * @param id 文章ID + * @param id 文章ID * @return 文章 */ Article getArticleByStatusAndId(@Param(value = "status") Integer status, @Param(value = "id") Integer id); @@ -101,8 +110,8 @@ public interface ArticleMapper { */ @Deprecated List
pageArticle(@Param(value = "status") Integer status, - @Param(value = "pageIndex") Integer pageIndex, - @Param(value = "pageSize") Integer pageSize); + @Param(value = "pageIndex") Integer pageIndex, + @Param(value = "pageSize") Integer pageSize); /** @@ -140,13 +149,12 @@ List
pageArticle(@Param(value = "status") Integer status, /** * 热评文章 * - * @param limit 查询数量 + * @param limit 查询数量 * @return 文章列表 */ List
listArticleByCommentCount(@Param(value = "limit") Integer limit); - /** * 更新文章的评论数 * @@ -195,7 +203,7 @@ List
findArticleByCategoryIds(@Param("categoryIds") List categ * @param limit 查询数量 * @return 列表 */ - List
listArticleByLimit(Integer limit); + List
listArticleByLimit(@Param("userId") Integer userId, @Param("limit") Integer limit); /** * 批量删除文章 @@ -204,4 +212,12 @@ List
findArticleByCategoryIds(@Param("categoryIds") List categ * @return 影响行数 */ Integer deleteBatch(@Param("ids") List ids); + + /** + * 获得一个用户的文章id集合 + * + * @param userId + * @return + */ + List listArticleIdsByUserId(Integer userId); } \ No newline at end of file diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/mapper/CommentMapper.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/mapper/CommentMapper.java index da94bca6..e8976b35 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/mapper/CommentMapper.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/mapper/CommentMapper.java @@ -4,6 +4,7 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.HashMap; import java.util.List; @Mapper @@ -55,7 +56,16 @@ public interface CommentMapper { * * @return 列表 */ - List listComment(); + List listComment(HashMap criteria); + + + /** + * 获得某个用户收到的评论 + * + * @return 列表 + */ + List getReceiveComment(List articleIds); + /** * 统计评论数 @@ -70,7 +80,8 @@ public interface CommentMapper { * @param limit 查询数量 * @return 列表 */ - List listRecentComment(@Param(value = "limit") Integer limit); + List listRecentComment(@Param(value = "userId") Integer userId, + @Param(value = "limit") Integer limit); /** * 获得评论的子评论 @@ -79,4 +90,22 @@ public interface CommentMapper { * @return 列表 */ List listChildComment(@Param(value = "id") Integer id); + + + /** + * 根据用户ID删除 + * + * @param userId 用户ID + * @return 影响函数 + */ + Integer deleteByUserId(Integer userId); + + + /** + * 根据文章ID删除 + * + * @param articleId 文章ID + * @return 影响函数 + */ + Integer deleteByArticleId(Integer articleId); } \ No newline at end of file diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/ArticleService.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/ArticleService.java index a4495d8e..f489bdce 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/ArticleService.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/ArticleService.java @@ -67,7 +67,7 @@ public interface ArticleService { * @param limit 查询数量 * @return 列表 */ - List
listRecentArticle(Integer limit); + List
listRecentArticle(Integer userId, Integer limit); /** diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/CommentService.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/CommentService.java index f66caae7..17613a83 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/CommentService.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/CommentService.java @@ -4,6 +4,7 @@ import com.liuyanzhao.ssm.blog.entity.Comment; import org.springframework.stereotype.Service; +import java.util.HashMap; import java.util.List; @@ -47,14 +48,20 @@ public interface CommentService { */ PageInfo listCommentByPage( Integer pageIndex, - Integer pageSize); + Integer pageSize, + HashMap criteria); /** - * 获得评论列表 + * 获得某个用户收到的评论 * + * @param pageIndex 第几页开始 + * @param pageSize 一页显示数量 * @return 列表 */ - List listComment(); + PageInfo listReceiveCommentByPage( + Integer pageIndex, + Integer pageSize, + Integer userId); /** @@ -84,7 +91,7 @@ PageInfo listCommentByPage( * @param limit 查询数量 * @return 列表 */ - List listRecentComment(Integer limit); + List listRecentComment(Integer userId, Integer limit); /** * 获得评论的子评论 diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/ArticleServiceImpl.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/ArticleServiceImpl.java index 5899dfc6..b1c5e94e 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/ArticleServiceImpl.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/ArticleServiceImpl.java @@ -1,17 +1,17 @@ package com.liuyanzhao.ssm.blog.service.impl; +import cn.hutool.core.util.RandomUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.liuyanzhao.ssm.blog.enums.ArticleCommentStatus; +import com.liuyanzhao.ssm.blog.mapper.*; import com.liuyanzhao.ssm.blog.service.ArticleService; import com.liuyanzhao.ssm.blog.entity.*; -import com.liuyanzhao.ssm.blog.mapper.ArticleCategoryRefMapper; -import com.liuyanzhao.ssm.blog.mapper.ArticleMapper; -import com.liuyanzhao.ssm.blog.mapper.ArticleTagRefMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; import java.util.ArrayList; import java.util.Date; @@ -28,15 +28,21 @@ @Slf4j public class ArticleServiceImpl implements ArticleService { - @Autowired(required = false) + @Autowired private ArticleMapper articleMapper; - @Autowired(required = false) + @Autowired private ArticleCategoryRefMapper articleCategoryRefMapper; - @Autowired(required = false) + @Autowired private ArticleTagRefMapper articleTagRefMapper; + @Autowired + private UserMapper userMapper; + + @Autowired + private CommentMapper commentMapper; + @Override public Integer countArticle(Integer status) { Integer count = 0; @@ -98,8 +104,8 @@ public List
listArticle(HashMap criteria) { } @Override - public List
listRecentArticle(Integer limit) { - return articleMapper.listArticleByLimit(limit); + public List
listRecentArticle(Integer userId, Integer limit) { + return articleMapper.listArticleByLimit(userId, limit); } @Override @@ -140,8 +146,15 @@ public void deleteArticleBatch(List ids) { } @Override + @Transactional(rollbackFor = Exception.class) public void deleteArticle(Integer id) { articleMapper.deleteById(id); + // 删除分类关联 + articleCategoryRefMapper.deleteByArticleId(id); + // 删除标签管理 + articleTagRefMapper.deleteByArticleId(id); + // 删除评论 + commentMapper.deleteByArticleId(id); } @@ -159,6 +172,8 @@ public PageInfo
pageArticle(Integer pageIndex, categoryList.add(Category.Default()); } articleList.get(i).setCategoryList(categoryList); + + articleList.get(i).setUser(userMapper.getUserById(articleList.get(i).getArticleUserId())); // //封装TagList // List tagList = articleTagRefMapper.listTagByArticleId(articleList.get(i).getArticleId()); // articleList.get(i).setTagList(tagList); @@ -216,6 +231,10 @@ public void insertArticle(Article article) { article.setArticleLikeCount(0); article.setArticleCommentCount(0); article.setArticleOrder(1); + if (StringUtils.isEmpty(article.getArticleThumbnail())) { + article.setArticleThumbnail("/img/thumbnail/random/img_" + RandomUtil.randomNumbers(1) + ".jpg"); + } + articleMapper.insert(article); //添加分类和文章关联 for (int i = 0; i < article.getCategoryList().size(); i++) { diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/CategoryServiceImpl.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/CategoryServiceImpl.java index 2efb300a..6cd6cd70 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/CategoryServiceImpl.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/CategoryServiceImpl.java @@ -23,10 +23,10 @@ @Slf4j public class CategoryServiceImpl implements CategoryService { - @Autowired(required = false) + @Autowired private CategoryMapper categoryMapper; - @Autowired(required = false) + @Autowired private ArticleCategoryRefMapper articleCategoryRefMapper; @Override diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/CommentServiceImpl.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/CommentServiceImpl.java index 89a66b2b..20f9015d 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/CommentServiceImpl.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/CommentServiceImpl.java @@ -13,6 +13,8 @@ import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; /** @@ -23,10 +25,10 @@ @Slf4j public class CommentServiceImpl implements CommentService { - @Autowired(required = false) + @Autowired private CommentMapper commentMapper; - @Autowired(required = false) + @Autowired private ArticleMapper articleMapper; @Override @@ -64,11 +66,11 @@ public Comment getCommentById(Integer id) { } @Override - public PageInfo listCommentByPage(Integer pageIndex, Integer pageSize) { + public PageInfo listCommentByPage(Integer pageIndex, Integer pageSize, HashMap criteria) { PageHelper.startPage(pageIndex, pageSize); List commentList = null; try { - commentList = commentMapper.listComment(); + commentList = commentMapper.listComment(criteria); for (int i = 0; i < commentList.size(); i++) { Article article = articleMapper.getArticleByStatusAndId(ArticleStatus.PUBLISH.getValue(), commentList.get(i).getCommentArticleId()); commentList.get(i).setArticle(article); @@ -81,15 +83,23 @@ public PageInfo listCommentByPage(Integer pageIndex, Integer pageSize) } @Override - public List listComment() { - List commentList = null; + public PageInfo listReceiveCommentByPage(Integer pageIndex, Integer pageSize, Integer userId) { + PageHelper.startPage(pageIndex, pageSize); + List commentList = new ArrayList<>(); try { - commentList = commentMapper.listComment(); + List articleIds = articleMapper.listArticleIdsByUserId(userId); + if (articleIds != null && articleIds.size() > 0) { + commentList = commentMapper.getReceiveComment(articleIds); + for (int i = 0; i < commentList.size(); i++) { + Article article = articleMapper.getArticleByStatusAndId(ArticleStatus.PUBLISH.getValue(), commentList.get(i).getCommentArticleId()); + commentList.get(i).setArticle(article); + } + } } catch (Exception e) { e.printStackTrace(); - log.error("获得评论列表失败:cause:{}", e); + log.error("分页获得评论失败,pageIndex:{}, pageSize:{}, cause:{}", pageIndex, pageSize, e); } - return commentList; + return new PageInfo<>(commentList); } @Override @@ -125,10 +135,10 @@ public Integer countComment() { } @Override - public List listRecentComment(Integer limit) { + public List listRecentComment(Integer userId, Integer limit) { List commentList = null; try { - commentList = commentMapper.listRecentComment(limit); + commentList = commentMapper.listRecentComment(userId, limit); for (int i = 0; i < commentList.size(); i++) { Article article = articleMapper.getArticleByStatusAndId(ArticleStatus.PUBLISH.getValue(), commentList.get(i).getCommentArticleId()); commentList.get(i).setArticle(article); diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/LinkServiceImpl.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/LinkServiceImpl.java index e26f8f4d..ef0ad3eb 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/LinkServiceImpl.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/LinkServiceImpl.java @@ -17,7 +17,7 @@ @Service public class LinkServiceImpl implements LinkService { - @Autowired(required = false) + @Autowired private LinkMapper linkMapper; @Override diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/MenuServiceImpl.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/MenuServiceImpl.java index 9ccf80e9..baf2cbdf 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/MenuServiceImpl.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/MenuServiceImpl.java @@ -16,7 +16,7 @@ public class MenuServiceImpl implements MenuService { - @Autowired(required = false) + @Autowired private MenuMapper menuMapper; @Override diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/NoticeServiceImpl.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/NoticeServiceImpl.java index d7155a6f..f460fcb0 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/NoticeServiceImpl.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/NoticeServiceImpl.java @@ -15,7 +15,7 @@ @Service public class NoticeServiceImpl implements NoticeService { - @Autowired(required = false) + @Autowired private NoticeMapper noticeMapper; @Override diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/OptionsServiceImpl.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/OptionsServiceImpl.java index 9bda54e9..de8892f1 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/OptionsServiceImpl.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/OptionsServiceImpl.java @@ -17,7 +17,7 @@ public class OptionsServiceImpl implements OptionsService { - @Autowired(required = false) + @Autowired private OptionsMapper optionsMapper; @Override diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/PageServiceImpl.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/PageServiceImpl.java index 41dbb1a1..2d2b8827 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/PageServiceImpl.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/PageServiceImpl.java @@ -16,7 +16,7 @@ @Service public class PageServiceImpl implements PageService { - @Autowired(required = false) + @Autowired private PageMapper pageMapper; @Override diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/TagServiceImpl.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/TagServiceImpl.java index eb6f38a9..6cc1bd6c 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/TagServiceImpl.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/TagServiceImpl.java @@ -20,10 +20,10 @@ @Slf4j public class TagServiceImpl implements TagService { - @Autowired(required = false) + @Autowired private TagMapper tagMapper; - @Autowired(required = false) + @Autowired private ArticleTagRefMapper articleTagRefMapper; @Override diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/UserServiceImpl.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/UserServiceImpl.java index 1513ac30..5fe8e2f5 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/UserServiceImpl.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/service/impl/UserServiceImpl.java @@ -1,11 +1,14 @@ package com.liuyanzhao.ssm.blog.service.impl; import com.liuyanzhao.ssm.blog.mapper.ArticleMapper; +import com.liuyanzhao.ssm.blog.mapper.CommentMapper; import com.liuyanzhao.ssm.blog.mapper.UserMapper; import com.liuyanzhao.ssm.blog.entity.User; +import com.liuyanzhao.ssm.blog.service.ArticleService; import com.liuyanzhao.ssm.blog.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.List; @@ -19,12 +22,17 @@ @Service public class UserServiceImpl implements UserService { - @Autowired(required = false) + @Autowired private UserMapper userMapper; - @Autowired(required = false) + @Autowired private ArticleMapper articleMapper; + @Autowired + private ArticleService articleService; + @Autowired + private CommentMapper commentMapper; + @Override public List listUser() { List userList = userMapper.listUser(); @@ -46,8 +54,19 @@ public void updateUser(User user) { } @Override + @Transactional(rollbackFor = Exception.class) public void deleteUser(Integer id) { + // 删除用户 userMapper.deleteById(id); + // 删除评论 + commentMapper.deleteByUserId(id); + // 删除文章 + List articleIds = articleMapper.listArticleIdsByUserId(id); + if (articleIds != null && articleIds.size() > 0) { + for (Integer articleId : articleIds) { + articleService.deleteArticle(articleId); + } + } } @Override diff --git a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/util/MyUtils.java b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/util/MyUtils.java index 122f1e21..49d7704e 100755 --- a/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/util/MyUtils.java +++ b/ForestBlog/src/main/java/com/liuyanzhao/ssm/blog/util/MyUtils.java @@ -88,4 +88,5 @@ public static String getGravatar(String email) { return avatar; } + } \ No newline at end of file diff --git a/ForestBlog/src/main/resources/db.properties b/ForestBlog/src/main/resources/db.properties index 212c7ce0..cec7879c 100755 --- a/ForestBlog/src/main/resources/db.properties +++ b/ForestBlog/src/main/resources/db.properties @@ -1,4 +1,5 @@ #MySQL -mysql.url=jdbc:mysql://127.0.0.1:3306/forest_blog?useUnicode=true&characterEncoding=utf8 +mysql.driver=com.mysql.cj.jdbc.Driver +mysql.url=jdbc:mysql://127.0.0.1:3306/forest_blog?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC mysql.username=root mysql.password=123456 diff --git a/ForestBlog/src/main/resources/log4j.properties b/ForestBlog/src/main/resources/log4j.properties deleted file mode 100644 index c6b73837..00000000 --- a/ForestBlog/src/main/resources/log4j.properties +++ /dev/null @@ -1,11 +0,0 @@ -# Configure logging for testing: optionally with log file - log4j.rootLogger=WARN, stdout, logfile - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n - -log4j.appender.logfile=org.apache.log4j.FileAppender -log4j.appender.logfile.File=target/ForestBlog.log -log4j.appender.logfile.layout=org.apache.log4j.PatternLayout -log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n \ No newline at end of file diff --git a/ForestBlog/src/main/resources/logback.xml b/ForestBlog/src/main/resources/logback.xml new file mode 100644 index 00000000..a7df509b --- /dev/null +++ b/ForestBlog/src/main/resources/logback.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread]%logger{56}.%method:%L -%msg%n + + + + + + ${log.base}/${log.moduleName}.log + + + + ${log.base}/archive/${log.moduleName}_all_%d{yyyy-MM-dd}.%i.log.zip + + + + ${log.max.size} + + + + + %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread]%logger{56}.%method:%L -%msg%n + + + + \ No newline at end of file diff --git a/ForestBlog/src/main/resources/mapper/ArticleMapper.xml b/ForestBlog/src/main/resources/mapper/ArticleMapper.xml index df5ed01b..aa2dda6d 100644 --- a/ForestBlog/src/main/resources/mapper/ArticleMapper.xml +++ b/ForestBlog/src/main/resources/mapper/ArticleMapper.xml @@ -15,19 +15,20 @@ + article article_id, article_user_id, article_title, article_content,article_summary, article_view_count, article_comment_count, article_like_count, article_create_time, - article_update_time, article_is_comment, article_status, article_order + article_update_time, article_is_comment, article_status, article_order, article_thumbnail SELECT - article.article_id, article.article_user_id, article.article_title, + distinct article.article_id, article.article_user_id, article.article_title, article.article_view_count, article.article_comment_count, article.article_like_count, article.article_create_time, article.article_update_time, article.article_is_comment, article.article_status, article.article_order, - article.article_summary + article.article_summary, article.article_thumbnail FROM article, article_category_ref article.article_status = 1 AND @@ -318,10 +324,24 @@ SELECT article_id, article_user_id, article_title, article_view_count, article_comment_count, article_like_count, article_create_time, - article_update_time, article_is_comment, article_status, article_order + article_update_time, article_is_comment, article_status, article_order, article_thumbnail FROM + + + article_user_id = #{userId} + + ORDER BY article_id DESC - LIMIT #{value} + LIMIT #{limit} + + + diff --git a/ForestBlog/src/main/resources/mapper/CommentMapper.xml b/ForestBlog/src/main/resources/mapper/CommentMapper.xml index 9d9d0382..266d4d17 100755 --- a/ForestBlog/src/main/resources/mapper/CommentMapper.xml +++ b/ForestBlog/src/main/resources/mapper/CommentMapper.xml @@ -15,6 +15,7 @@ + comment @@ -22,7 +23,7 @@ comment_id, comment_pid, comment_pname, comment_article_id, comment_author_name, comment_author_email, comment_author_url, comment_author_avatar, comment_content, comment_agent, - comment_ip,comment_create_time, comment_role + comment_ip,comment_create_time, comment_role,comment_user_id + + @@ -107,7 +141,11 @@ FROM - WHERE comment_role = 0 + + + comment_user_id = #{userId} + + ORDER BY comment_id DESC LIMIT #{limit} diff --git a/ForestBlog/src/main/resources/mapper/UserMapper.xml b/ForestBlog/src/main/resources/mapper/UserMapper.xml index 07c53bf3..aab46d88 100755 --- a/ForestBlog/src/main/resources/mapper/UserMapper.xml +++ b/ForestBlog/src/main/resources/mapper/UserMapper.xml @@ -13,13 +13,14 @@ + user user_id, user_name, user_pass, user_nickname, user_email, user_url, user_avatar, - user_last_login_ip, user_register_time, user_last_login_time, user_status + user_last_login_ip, user_register_time, user_last_login_time, user_status, user_role + + +
@@ -107,16 +121,45 @@
-
- 温馨提示: - 1、插入代码前,可以点击 代码高亮,将代码转成HTML格式 -
+ + + + + +<%@ include file="../Public/framework.jsp" %> diff --git a/ForestBlog/src/main/webapp/WEB-INF/view/Admin/User/insert.jsp b/ForestBlog/src/main/webapp/WEB-INF/view/Admin/User/insert.jsp index 3a4ce0a1..bd1e429c 100755 --- a/ForestBlog/src/main/webapp/WEB-INF/view/Admin/User/insert.jsp +++ b/ForestBlog/src/main/webapp/WEB-INF/view/Admin/User/insert.jsp @@ -6,7 +6,7 @@ <%@ taglib prefix="rapid" uri="http://www.rapid-framework.org.cn/rapid" %> - - 编辑用户 + - 添加用户 + + + + + +
+

${options.optionSiteTitle}

+
+

+ +

+

+ +

+

+ +

+

+ +

+

+ +

+

+ +

+
+ +

← 返回到风吟博客 | 登录

+ +
+ + +
+ + + + + + diff --git a/ForestBlog/src/main/webapp/WEB-INF/view/Home/Error/403.jsp b/ForestBlog/src/main/webapp/WEB-INF/view/Home/Error/403.jsp new file mode 100755 index 00000000..362d852b --- /dev/null +++ b/ForestBlog/src/main/webapp/WEB-INF/view/Home/Error/403.jsp @@ -0,0 +1,62 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8" %> + + + + + + 403 没有权限操作 + + + +
+
+
+

+ 403很抱歉,您没有权限操作! +

+
+
+

可能原因:

+
    +
  1. 访问了其他用户的数据
  2. +
  3. 系统异常
  4. +
  5. 输入的网址不正确
  6. +
+
+
+

可以尝试:

+
    +
  1. 返回首页
  2. +
  3. 留言反馈
  4. +
  5. + 联系站长 +
  6. +
+
+
+
+
+
+ + \ No newline at end of file diff --git a/ForestBlog/src/main/webapp/WEB-INF/view/Home/Page/articleDetail.jsp b/ForestBlog/src/main/webapp/WEB-INF/view/Home/Page/articleDetail.jsp index 1656618f..b05ac99d 100755 --- a/ForestBlog/src/main/webapp/WEB-INF/view/Home/Page/articleDetail.jsp +++ b/ForestBlog/src/main/webapp/WEB-INF/view/Home/Page/articleDetail.jsp @@ -120,7 +120,7 @@