diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..3a45660
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,19 @@
+<<<<<<< HEAD
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+=======
+# Default ignored files
+/shelf/
+/workspace.xml
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+>>>>>>> lenshiwei_branch
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..182318b
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+ArticleServiceImpl.java
\ No newline at end of file
diff --git a/.idea/ForestBlog.iml b/.idea/ForestBlog.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/.idea/ForestBlog.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..8c49274
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,13 @@
+
+
+<<<<<<< HEAD
+
+=======
+
+
+
+
+>>>>>>> lenshiwei_branch
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..7e94b14
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..1cc2281
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ "associatedIndex": 7
+}
+
+
+
+
+
+ {
+ "keyToString": {
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "git-widget-placeholder": "develop",
+ "kotlin-language-version-configured": "true",
+ "last_opened_file_path": "D:/下载/ForestBlog-master",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "vue.rearranger.settings.migration": "true"
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+ 1733319500475
+
+
+ 1733319500475
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cs.txt b/cs.txt
deleted file mode 100644
index 58c9bdf..0000000
--- a/cs.txt
+++ /dev/null
@@ -1 +0,0 @@
-111
diff --git a/src/java/controller/admin/AdminController.java b/src/java/controller/admin/AdminController.java
new file mode 100644
index 0000000..90882f8
--- /dev/null
+++ b/src/java/controller/admin/AdminController.java
@@ -0,0 +1,248 @@
+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;
+import org.json.JSONObject;
+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;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static com.liuyanzhao.ssm.blog.util.MyUtils.getIpAddr;
+
+/**
+ * @author liuyanzhao
+ */
+@Controller
+public class AdminController {
+ @Autowired
+ private UserService userService;
+
+ @Autowired
+ private ArticleService articleService;
+
+ @Autowired
+ private CommentService commentService;
+
+ /**
+ * 后台首页
+ *
+ * @return
+ */
+ @RequestMapping("/admin")
+ 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(userId, 5);
+ model.addAttribute("articleList", articleList);
+
+ //评论列表
+ List commentList = commentService.listRecentComment(userId, 5);
+ model.addAttribute("commentList", commentList);
+ return "Admin/index";
+ }
+
+ /**
+ * 登录页面显示
+ *
+ * @return
+ */
+ @RequestMapping("/login")
+ public String
+ loginPage() {
+ return "Admin/login";
+ }
+
+
+ /**
+ * 登录页面显示
+ *
+ * @return
+ */
+ @RequestMapping("/register")
+ public String registerPage() {
+ return "Admin/register";
+ }
+
+ /**
+ * 登录验证
+ *
+ * @param request
+ * @param response
+ * @return
+ */
+ @RequestMapping(value = "/loginVerify", method = RequestMethod.POST, produces = {"text/plain;charset=UTF-8"})
+ @ResponseBody
+ 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", "密码错误!");
+ } else if (user.getUserStatus() == 0) {
+ map.put("code", 0);
+ map.put("msg", "账号已禁用!");
+ } else {
+ //登录成功
+ map.put("code", 1);
+ map.put("msg", "");
+ //添加session
+ request.getSession().setAttribute("user", user);
+ //添加cookie
+ if (rememberme != null) {
+ //创建两个Cookie对象
+ Cookie nameCookie = new Cookie("username", username);
+ //设置Cookie的有效期为3天
+ nameCookie.setMaxAge(60 * 60 * 24 * 3);
+ Cookie pwdCookie = new Cookie("password", password);
+ pwdCookie.setMaxAge(60 * 60 * 24 * 3);
+ response.addCookie(nameCookie);
+ response.addCookie(pwdCookie);
+ }
+ user.setUserLastLoginTime(new Date());
+ user.setUserLastLoginIp(getIpAddr(request));
+ userService.updateUser(user);
+
+ }
+ String result = new JSONObject(map).toString();
+ 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("注册成功");
+ }
+
+ /**
+ * 退出登录
+ *
+ * @param session
+ * @return
+ */
+ @RequestMapping(value = "/admin/logout")
+ 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/src/java/controller/admin/BackArticleController.java b/src/java/controller/admin/BackArticleController.java
new file mode 100644
index 0000000..55d82cc
--- /dev/null
+++ b/src/java/controller/admin/BackArticleController.java
@@ -0,0 +1,296 @@
+package com.liuyanzhao.ssm.blog.controller.admin;
+
+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;
+
+import com.liuyanzhao.ssm.blog.entity.Category;
+import com.liuyanzhao.ssm.blog.entity.Tag;
+import com.liuyanzhao.ssm.blog.entity.User;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+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;
+
+
+/**
+ * @author liuyanzhao
+ */
+@Controller
+@RequestMapping("/admin/article")
+public class BackArticleController {
+ @Autowired
+ private ArticleService articleService;
+
+ @Autowired
+ private TagService tagService;
+
+ @Autowired
+ private CategoryService categoryService;
+
+ /**
+ * 后台文章列表显示
+ *
+ * @return modelAndView
+ */
+ @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,
+ HttpSession session) {
+ HashMap criteria = new HashMap<>(1);
+ if (status == null) {
+ model.addAttribute("pageUrlPrefix", "/admin/article?pageIndex");
+ } else {
+ 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";
+ }
+
+
+ /**
+ * 后台添加文章页面显示
+ *
+ * @return
+ */
+ @RequestMapping(value = "/insert")
+ public String insertArticleView(Model model) {
+ List categoryList = categoryService.listCategory();
+ List tagList = tagService.listTag();
+ model.addAttribute("categoryList", categoryList);
+ model.addAttribute("tagList", tagList);
+ return "Admin/Article/insert";
+ }
+
+ /**
+ * 后台添加文章提交操作
+ *
+ * @param articleParam
+ * @return
+ */
+ @RequestMapping(value = "/insertSubmit", method = RequestMethod.POST)
+ public String insertArticleSubmit(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/article";
+ }
+
+
+ /**
+ * 删除文章
+ *
+ * @param id 文章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);
+ }
+
+
+ /**
+ * 编辑文章页面显示
+ *
+ * @param id
+ * @return
+ */
+ @RequestMapping(value = "/edit/{id}")
+ public String editArticleView(@PathVariable("id") Integer id, Model model, HttpSession session) {
+
+ Article article = articleService.getArticleByStatusAndId(null, id);
+ 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();
+ model.addAttribute("categoryList", categoryList);
+
+ List tagList = tagService.listTag();
+ model.addAttribute("tagList", tagList);
+
+ return "Admin/Article/edit";
+ }
+
+
+ /**
+ * 编辑文章提交
+ *
+ * @param articleParam
+ * @return
+ */
+ @RequestMapping(value = "/editSubmit", method = RequestMethod.POST)
+ 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());
+ article.setArticleStatus(articleParam.getArticleStatus());
+ //文章摘要
+ int summaryLength = 150;
+ String summaryText = HtmlUtil.cleanHtmlTag(article.getArticleContent());
+ if (summaryText.length() > summaryLength) {
+ String summary = summaryText.substring(0, summaryLength);
+ article.setArticleSummary(summary);
+ } else {
+ article.setArticleSummary(summaryText);
+ }
+ //填充分类
+ 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.updateArticleDetail(article);
+ 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/src/java/controller/admin/BackCategoryController.java b/src/java/controller/admin/BackCategoryController.java
new file mode 100644
index 0000000..2ec0751
--- /dev/null
+++ b/src/java/controller/admin/BackCategoryController.java
@@ -0,0 +1,110 @@
+package com.liuyanzhao.ssm.blog.controller.admin;
+
+
+import com.liuyanzhao.ssm.blog.entity.Category;
+
+import com.liuyanzhao.ssm.blog.service.ArticleService;
+import com.liuyanzhao.ssm.blog.service.CategoryService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+
+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.servlet.ModelAndView;
+
+import java.util.List;
+
+
+/**
+ * @author liuyanzhao
+ */
+@Controller
+@RequestMapping("/admin/category")
+public class BackCategoryController {
+
+ @Autowired
+ private ArticleService articleService;
+
+
+ @Autowired
+ private CategoryService categoryService;
+
+ /**
+ * 后台分类列表显示
+ *
+ * @return
+ */
+ @RequestMapping(value = "")
+ public ModelAndView categoryList() {
+ ModelAndView modelandview = new ModelAndView();
+ List categoryList = categoryService.listCategoryWithCount();
+ modelandview.addObject("categoryList",categoryList);
+ modelandview.setViewName("Admin/Category/index");
+ return modelandview;
+
+ }
+
+
+ /**
+ * 后台添加分类提交
+ *
+ * @param category
+ * @return
+ */
+ @RequestMapping(value = "/insertSubmit",method = RequestMethod.POST)
+ public String insertCategorySubmit(Category category) {
+ categoryService.insertCategory(category);
+ return "redirect:/admin/category";
+ }
+
+ /**
+ * 删除分类
+ *
+ * @param id
+ * @return
+ */
+ @RequestMapping(value = "/delete/{id}")
+ public String deleteCategory(@PathVariable("id") Integer id) {
+ //禁止删除有文章的分类
+ int count = articleService.countArticleByCategoryId(id);
+
+ if (count == 0) {
+ categoryService.deleteCategory(id);
+ }
+ return "redirect:/admin/category";
+ }
+
+ /**
+ * 编辑分类页面显示
+ *
+ * @param id
+ * @return
+ */
+ @RequestMapping(value = "/edit/{id}")
+ public ModelAndView editCategoryView(@PathVariable("id") Integer id) {
+ ModelAndView modelAndView = new ModelAndView();
+
+ Category category = categoryService.getCategoryById(id);
+ modelAndView.addObject("category",category);
+
+ List categoryList = categoryService.listCategoryWithCount();
+ modelAndView.addObject("categoryList",categoryList);
+
+ modelAndView.setViewName("Admin/Category/edit");
+ return modelAndView;
+ }
+
+ /**
+ * 编辑分类提交
+ *
+ * @param category 分类
+ * @return 重定向
+ */
+ @RequestMapping(value = "/editSubmit",method = RequestMethod.POST)
+ public String editCategorySubmit(Category category) {
+ categoryService.updateCategory(category);
+ return "redirect:/admin/category";
+ }
+}
diff --git a/src/java/controller/admin/BackCommentController.java b/src/java/controller/admin/BackCommentController.java
new file mode 100644
index 0000000..ebf5e59
--- /dev/null
+++ b/src/java/controller/admin/BackCommentController.java
@@ -0,0 +1,218 @@
+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;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import java.util.*;
+
+
+/**
+ * @author liuyanzhao
+ */
+@Controller
+@RequestMapping("/admin/comment")
+public class BackCommentController {
+
+ @Autowired
+ private CommentService commentService;
+
+ @Autowired
+ private ArticleService articleService;
+
+ /**
+ * 评论页面
+ * 我发送的评论
+ *
+ * @param pageIndex 页码
+ * @param pageSize 页大小
+ * @return modelAndView
+ */
+ @RequestMapping(value = "")
+ 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");
+ return "Admin/Comment/index";
+ }
+
+
+ /**
+ * 添加评论
+ *
+ * @param request
+ * @param comment
+ */
+ @RequestMapping(value = "/insert", method = {RequestMethod.POST}, produces = {"text/plain;charset=UTF-8"})
+ @ResponseBody
+ 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);
+ //更新文章的评论数
+ articleService.updateCommentCount(article.getArticleId());
+ }
+
+ /**
+ * 删除评论
+ *
+ * @param id 批量ID
+ */
+ @RequestMapping(value = "/delete/{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);
+ //删除其子评论
+ List childCommentList = commentService.listChildComment(id);
+ for (int i = 0; i < childCommentList.size(); i++) {
+ commentService.deleteComment(childCommentList.get(i).getCommentId());
+ }
+ //更新文章的评论数
+ Article article = articleService.getArticleByStatusAndId(null, comment.getCommentArticleId());
+ articleService.updateCommentCount(article.getArticleId());
+ }
+
+ /**
+ * 编辑评论页面显示
+ *
+ * @param id
+ * @return
+ */
+ @RequestMapping(value = "/edit/{id}")
+ 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";
+ }
+
+
+ /**
+ * 编辑评论提交
+ *
+ * @param comment
+ * @return
+ */
+ @RequestMapping(value = "/editSubmit", method = RequestMethod.POST)
+ 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";
+ }
+
+
+ /**
+ * 回复评论页面显示
+ *
+ * @param id
+ * @return
+ */
+ @RequestMapping(value = "/reply/{id}")
+ public String replyCommentView(@PathVariable("id") Integer id, Model model) {
+ Comment comment = commentService.getCommentById(id);
+ model.addAttribute("comment", comment);
+ return "Admin/Comment/reply";
+ }
+
+ /**
+ * 回复评论提交
+ *
+ * @param request
+ * @param comment
+ * @return
+ */
+ @RequestMapping(value = "/replySubmit", method = RequestMethod.POST)
+ 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/src/java/controller/admin/BackLinkController.java b/src/java/controller/admin/BackLinkController.java
new file mode 100644
index 0000000..65bba8e
--- /dev/null
+++ b/src/java/controller/admin/BackLinkController.java
@@ -0,0 +1,121 @@
+package com.liuyanzhao.ssm.blog.controller.admin;
+
+
+import com.liuyanzhao.ssm.blog.entity.Link;
+import com.liuyanzhao.ssm.blog.service.LinkService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+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.servlet.ModelAndView;
+
+import java.util.Date;
+import java.util.List;
+
+
+/**
+ * @author liuyanzhao
+ */
+@Controller
+@RequestMapping("/admin/link")
+public class BackLinkController {
+
+ @Autowired
+ private LinkService linkService;
+
+ /**
+ * 后台链接列表显示
+ *
+ * @return modelAndView
+ */
+ @RequestMapping(value = "")
+ public ModelAndView linkList() {
+ ModelAndView modelandview = new ModelAndView();
+
+ List linkList = linkService.listLink(null);
+ modelandview.addObject("linkList",linkList);
+
+ modelandview.setViewName("Admin/Link/index");
+ return modelandview;
+
+ }
+
+ /**
+ * 后台添加链接页面显示
+ *
+ * @return modelAndView
+ */
+ @RequestMapping(value = "/insert")
+ public ModelAndView insertLinkView() {
+ ModelAndView modelAndView = new ModelAndView();
+
+ List linkList = linkService.listLink(null);
+ modelAndView.addObject("linkList",linkList);
+
+ modelAndView.setViewName("Admin/Link/insert");
+ return modelAndView;
+ }
+
+ /**
+ * 后台添加链接页面提交
+ *
+ * @param link 链接
+ * @return 响应
+ */
+ @RequestMapping(value = "/insertSubmit",method = RequestMethod.POST)
+ public String insertLinkSubmit(Link link) {
+ link.setLinkCreateTime(new Date());
+ link.setLinkUpdateTime(new Date());
+ link.setLinkStatus(1);
+ linkService.insertLink(link);
+ return "redirect:/admin/link/insert";
+ }
+
+ /**
+ * 删除链接
+ *
+ * @param id 链接ID
+ * @return 响应
+ */
+ @RequestMapping(value = "/delete/{id}")
+ public String deleteLink(@PathVariable("id") Integer id) {
+
+ linkService.deleteLink(id);
+ return "redirect:/admin/link";
+ }
+
+ /**
+ * 编辑链接页面显示
+ *
+ * @param id
+ * @return modelAndVIew
+ */
+ @RequestMapping(value = "/edit/{id}")
+ public ModelAndView editLinkView(@PathVariable("id") Integer id) {
+ ModelAndView modelAndView = new ModelAndView();
+
+ Link linkCustom = linkService.getLinkById(id);
+ modelAndView.addObject("linkCustom",linkCustom);
+
+ List linkList = linkService.listLink(null);
+ modelAndView.addObject("linkList",linkList);
+
+ modelAndView.setViewName("Admin/Link/edit");
+ return modelAndView;
+ }
+
+
+ /**
+ * 编辑链接提交
+ *
+ * @param link 链接
+ * @return 响应
+ */
+ @RequestMapping(value = "/editSubmit",method = RequestMethod.POST)
+ public String editLinkSubmit(Link link) {
+ link.setLinkUpdateTime(new Date());
+ linkService.updateLink(link);
+ return "redirect:/admin/link";
+ }
+}
diff --git a/src/java/controller/admin/BackMenuController.java b/src/java/controller/admin/BackMenuController.java
new file mode 100644
index 0000000..076aae2
--- /dev/null
+++ b/src/java/controller/admin/BackMenuController.java
@@ -0,0 +1,100 @@
+package com.liuyanzhao.ssm.blog.controller.admin;
+
+import com.liuyanzhao.ssm.blog.entity.Menu;
+import com.liuyanzhao.ssm.blog.enums.MenuLevel;
+import com.liuyanzhao.ssm.blog.service.MenuService;
+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.servlet.ModelAndView;
+
+import java.util.List;
+
+/**
+ * @author liuyanzhao
+ */
+@Controller
+@RequestMapping("/admin/menu")
+public class BackMenuController {
+
+ @Autowired
+ private MenuService menuService;
+
+ /**
+ * 后台菜单列表显示
+ *
+ * @return
+ */
+ @RequestMapping(value = "")
+ public String menuList(Model model) {
+ List