Compare commits

...

43 Commits

Author SHA1 Message Date
lee ee3c715ee9 q
1 year ago
冷世伟 8946c7f0e1 Merge branch 'lenshiwei_branch' into develop
1 year ago
lee 0d6532ad75 Merge branch 'develop' of https://bdgit.educoder.net/p48fytmwz/ForestBlog into develop
1 year ago
lee 3276a8da0e Merge branch 'lijunjie_branch' into develop
1 year ago
ZSY b95ad2edf2 Merge branch 'zhangshiyu_branch' into develop
1 year ago
ZSY 642e761dcb 1
1 year ago
冷世伟 1a8a81e7b8 1
1 year ago
ZSY b7c7def936 1
1 year ago
ZSY a0495c56e8 Merge branch 'zhangshiyu_branch' of https://bdgit.educoder.net/p48fytmwz/ForestBlog into zhangshiyu_branch
1 year ago
ZSY 7dad49b774 1
1 year ago
冷世伟 31809f2a0b l
1 year ago
ZSY 99e82147d0 1
1 year ago
ZSY aae5db0d57 1
1 year ago
冷世伟 050980342e 1
1 year ago
ZSY 13dac81762 1
1 year ago
冷世伟 506ee6ed08 1
1 year ago
ZSY d5581f6dad 1
1 year ago
ZSY c3f0356195 1
1 year ago
ZSY e748286c9e 1
1 year ago
ZSY 5274a76256 1
1 year ago
ZSY bac6e2d3d0 1
1 year ago
ZSY 369ebcb26c 1
1 year ago
ZSY 0a12a6f064 1
1 year ago
ZSY a63ef07ff6 1
1 year ago
ZSY d89ccdb266 1
1 year ago
ZSY 7abec2fb27 1
1 year ago
p48fytmwz da65ae660e Merge pull request 'test' (#2) from zhangshiyu_branch into develop
1 year ago
ZSY 600647deb3 1
1 year ago
p48fytmwz 76e0676749 Merge pull request 'test' (#1) from lijunjie_branch into zhangshiyu_branch
1 year ago
ZSY 3f9b859529 1
1 year ago
ZSY a2bf946a1e test
1 year ago
ZSY bcb6caec93 1
1 year ago
ZSY 679ad4fbd8 1
1 year ago
ZSY 182542e719 1
1 year ago
ZSY 43820f6a25 1
1 year ago
ZSY cf605bb3a7 2
1 year ago
ZSY 81b22a1376 xiugai
1 year ago
p48fytmwz 431b09bb7e Add doc
1 year ago
p48fytmwz 77e670efa3 Add src
1 year ago
p48fytmwz 199d8fca54 Add doc
1 year ago
p48fytmwz be4bfd9842 Add src
1 year ago
p48fytmwz 3d53fdc8d9 Add doc
1 year ago
p48fytmwz 499a2c56c8 Add src
1 year ago

19
.idea/.gitignore vendored

@ -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

@ -0,0 +1 @@
ArticleServiceImpl.java

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<<<<<<< HEAD
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
=======
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_13" project-jdk-name="13" project-jdk-type="JavaSDK">
>>>>>>> lenshiwei_branch
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="690df2e4-065b-4e1e-9ecc-de15c4a25040" name="更改" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 7
}</component>
<component name="ProjectId" id="2pkoas9hD1WLgDh1lyVWy1g01SE" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;develop&quot;,
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;D:/下载/ForestBlog-master&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}</component>
<component name="SharedIndexes">
<attachedChunks>
<set>
<option value="bundled-jdk-9823dce3aa75-28b599e66164-intellij.indexing.shared.core-IU-242.23726.103" />
<option value="bundled-js-predefined-d6986cc7102b-5c90d61e3bab-JavaScript-IU-242.23726.103" />
</set>
</attachedChunks>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="应用程序级" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="默认任务">
<changelist id="690df2e4-065b-4e1e-9ecc-de15c4a25040" name="更改" comment="" />
<created>1733319500475</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1733319500475</updated>
<workItem from="1733319501582" duration="660000" />
<workItem from="1733369308674" duration="84000" />
<workItem from="1733550125047" duration="19000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
</project>

@ -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<Article> articleList = articleService.listRecentArticle(userId, 5);
model.addAttribute("articleList", articleList);
//评论列表
List<Comment> 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<String, Object> map = new HashMap<String, Object>();
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";
}
}

@ -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<String, Object> 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<Article> articlePageInfo = articleService.pageArticle(pageIndex, pageSize, criteria);
model.addAttribute("pageInfo", articlePageInfo);
return "Admin/Article/index";
}
/**
*
*
* @return
*/
@RequestMapping(value = "/insert")
public String insertArticleView(Model model) {
List<Category> categoryList = categoryService.listCategory();
List<Tag> 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<Category> 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<Tag> 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<Category> categoryList = categoryService.listCategory();
model.addAttribute("categoryList", categoryList);
List<Tag> 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<Category> 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<Tag> 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<Category> 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<Tag> 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";
}
}

@ -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<Category> 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<Category> 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";
}
}

@ -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<String, Object> criteria = new HashMap<>();
if (!UserRole.ADMIN.getValue().equals(user.getUserRole())) {
// 用户查询自己的文章, 管理员查询所有的
criteria.put("userId", user.getUserId());
}
PageInfo<Comment> 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<Comment> 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<Comment> 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";
}
}

@ -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<Link> 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<Link> 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<Link> 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";
}
}

@ -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<Menu> menuList = menuService.listMenu();
model.addAttribute("menuList",menuList);
return "Admin/Menu/index";
}
/**
*
*
* @param menu
* @return
*/
@RequestMapping(value = "/insertSubmit",method = RequestMethod.POST)
public String insertMenuSubmit(Menu menu) {
if(menu.getMenuOrder() == null) {
menu.setMenuOrder(MenuLevel.TOP_MENU.getValue());
}
menuService.insertMenu(menu);
return "redirect:/admin/menu";
}
/**
*
*
* @param id
* @return
*/
@RequestMapping(value = "/delete/{id}")
public String deleteMenu(@PathVariable("id") Integer id) {
menuService.deleteMenu(id);
return "redirect:/admin/menu";
}
/**
*
*
* @param id
* @return
*/
@RequestMapping(value = "/edit/{id}")
public ModelAndView editMenuView(@PathVariable("id") Integer id) {
ModelAndView modelAndView = new ModelAndView();
Menu menu = menuService.getMenuById(id);
modelAndView.addObject("menu",menu);
List<Menu> menuList = menuService.listMenu();
modelAndView.addObject("menuList",menuList);
modelAndView.setViewName("Admin/Menu/edit");
return modelAndView;
}
/**
*
*
* @param menu
* @return
*/
@RequestMapping(value = "/editSubmit",method = RequestMethod.POST)
public String editMenuSubmit(Menu menu) {
menuService.updateMenu(menu);
return "redirect:/admin/menu";
}
}

@ -0,0 +1,105 @@
package com.liuyanzhao.ssm.blog.controller.admin;
import com.liuyanzhao.ssm.blog.entity.Notice;
import com.liuyanzhao.ssm.blog.enums.NoticeStatus;
import com.liuyanzhao.ssm.blog.service.NoticeService;
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 java.util.Date;
import java.util.List;
@Controller
@RequestMapping("/admin/notice")
public class BackNoticeController {
@Autowired
private NoticeService noticeService;
/**
*
*
* @return
*/
@RequestMapping(value = "")
public String index(Model model) {
List<Notice> noticeList = noticeService.listNotice(null);
model.addAttribute("noticeList", noticeList);
return "Admin/Notice/index";
}
/**
*
*
* @return
*/
@RequestMapping(value = "/insert")
public String insertNoticeView() {
return "Admin/Notice/insert";
}
/**
*
*
* @param notice
* @return
*/
@RequestMapping(value = "/insertSubmit", method = RequestMethod.POST)
public String insertNoticeSubmit(Notice notice) {
notice.setNoticeCreateTime(new Date());
notice.setNoticeUpdateTime(new Date());
notice.setNoticeStatus(NoticeStatus.NORMAL.getValue());
notice.setNoticeOrder(1);
noticeService.insertNotice(notice);
return "redirect:/admin/notice";
}
/**
*
*
* @param id
* @return
*/
@RequestMapping(value = "/delete/{id}")
public String deleteNotice(@PathVariable("id") Integer id) {
noticeService.deleteNotice(id);
return "redirect:/admin/notice";
}
/**
*
*
* @param id
* @return
*/
@RequestMapping(value = "/edit/{id}")
public String editNoticeView(@PathVariable("id") Integer id, Model model) {
Notice notice = noticeService.getNoticeById(id);
model.addAttribute("notice", notice);
return "Admin/Notice/edit";
}
/**
*
*
* @param notice
* @return
*/
@RequestMapping(value = "/editSubmit", method = RequestMethod.POST)
public String editNoticeSubmit(Notice notice) {
notice.setNoticeUpdateTime(new Date());
noticeService.updateNotice(notice);
return "redirect:/admin/notice";
}
}

@ -0,0 +1,71 @@
package com.liuyanzhao.ssm.blog.controller.admin;
import com.liuyanzhao.ssm.blog.entity.Options;
import com.liuyanzhao.ssm.blog.service.OptionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
/**
* @author liuyanzhao
*/
@Controller
@RequestMapping("/admin/options")
public class BackOptionsController {
@Autowired
private OptionsService optionsService;
/**
*
*
* @return
*/
@RequestMapping(value = "")
public ModelAndView index() {
ModelAndView modelAndView = new ModelAndView();
Options option = optionsService.getOptions();
modelAndView.addObject("option",option);
modelAndView.setViewName("Admin/Options/index");
return modelAndView;
}
/**
*
*
* @return
*/
@RequestMapping(value = "/edit")
public ModelAndView editOptionView() {
ModelAndView modelAndView = new ModelAndView();
Options option = optionsService.getOptions();
modelAndView.addObject("option",option);
modelAndView.setViewName("Admin/Options/edit");
return modelAndView;
}
/**
*
*
* @param options
* @return
*/
@RequestMapping(value = "/editSubmit",method = RequestMethod.POST)
public String editOptionSubmit(Options options) {
//如果记录不存在,那就新建
Options optionsCustom = optionsService.getOptions();
if(optionsCustom.getOptionId()==null) {
optionsService.insertOptions(options);
} else {
optionsService.updateOptions(options);
}
return "redirect:/admin/options";
}
}

@ -0,0 +1,128 @@
package com.liuyanzhao.ssm.blog.controller.admin;
import com.liuyanzhao.ssm.blog.entity.Page;
import com.liuyanzhao.ssm.blog.enums.PageStatus;
import com.liuyanzhao.ssm.blog.service.PageService;
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;
import java.util.Objects;
/**
* @author liuyanzhao
*/
@Controller
@RequestMapping("/admin/page")
public class BackPageController {
@Autowired
private PageService pageService;
/**
*
*
* @return
*/
@RequestMapping(value = "")
public ModelAndView index() {
ModelAndView modelAndView = new ModelAndView();
List<Page> pageList = pageService.listPage(null);
modelAndView.addObject("pageList", pageList);
modelAndView.setViewName("Admin/Page/index");
return modelAndView;
}
/**
*
*
* @return
*/
@RequestMapping(value = "/insert")
public ModelAndView insertPageView() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("Admin/Page/insert");
return modelAndView;
}
/**
*
*
* @param page
* @return
*/
@RequestMapping(value = "/insertSubmit", method = RequestMethod.POST)
public String insertPageSubmit(Page page) {
//判断别名是否存在
Page checkPage = pageService.getPageByKey(null, page.getPageKey());
if (checkPage == null) {
page.setPageCreateTime(new Date());
page.setPageUpdateTime(new Date());
page.setPageStatus(PageStatus.NORMAL.getValue());
pageService.insertPage(page);
}
return "redirect:/admin/page";
}
/**
*
*
* @param id
* @return
*/
@RequestMapping(value = "/delete/{id}")
public String deletePage(@PathVariable("id") Integer id) {
//调用service批量删除
pageService.deletePage(id);
return "redirect:/admin/page";
}
/**
*
*
* @param id
* @return
*/
@RequestMapping(value = "/edit/{id}")
public ModelAndView editPageView(@PathVariable("id") Integer id) {
ModelAndView modelAndView = new ModelAndView();
Page page = pageService.getPageById(id);
modelAndView.addObject("page", page);
modelAndView.setViewName("Admin/Page/edit");
return modelAndView;
}
/**
*
*
* @param page
* @return
*/
@RequestMapping(value = "/editSubmit", method = RequestMethod.POST)
public String editPageSubmit(Page page) {
Page checkPage = pageService.getPageByKey(null, page.getPageKey());
//判断别名是否存在且不是这篇文章
if (Objects.equals(checkPage.getPageId(), page.getPageId())) {
page.setPageUpdateTime(new Date());
pageService.updatePage(page);
}
return "redirect:/admin/page";
}
}

@ -0,0 +1,105 @@
package com.liuyanzhao.ssm.blog.controller.admin;
import com.liuyanzhao.ssm.blog.entity.Tag;
import com.liuyanzhao.ssm.blog.service.ArticleService;
import com.liuyanzhao.ssm.blog.service.TagService;
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/tag")
public class BackTagController {
@Autowired
private ArticleService articleService;
@Autowired
private TagService tagService;
/**
*
* @return
*/
@RequestMapping(value = "")
public ModelAndView index() {
ModelAndView modelandview = new ModelAndView();
List<Tag> tagList = tagService.listTagWithCount();
modelandview.addObject("tagList",tagList);
modelandview.setViewName("Admin/Tag/index");
return modelandview;
}
/**
*
*
* @param tag
* @return
*/
@RequestMapping(value = "/insertSubmit",method = RequestMethod.POST)
public String insertTagSubmit(Tag tag) {
tagService.insertTag(tag);
return "redirect:/admin/tag";
}
/**
*
*
* @param id ID
* @return
*/
@RequestMapping(value = "/delete/{id}")
public String deleteTag(@PathVariable("id") Integer id) {
Integer count = articleService.countArticleByTagId(id);
if (count == 0) {
tagService.deleteTag(id);
}
return "redirect:/admin/tag";
}
/**
*
*
* @param id
* @return
*/
@RequestMapping(value = "/edit/{id}")
public ModelAndView editTagView(@PathVariable("id") Integer id) {
ModelAndView modelAndView = new ModelAndView();
Tag tag = tagService.getTagById(id);
modelAndView.addObject("tag",tag);
List<Tag> tagList = tagService.listTagWithCount();
modelAndView.addObject("tagList",tagList);
modelAndView.setViewName("Admin/Tag/edit");
return modelAndView;
}
/**
*
*
* @param tag
* @return
*/
@RequestMapping(value = "/editSubmit",method = RequestMethod.POST)
public String editTagSubmit(Tag tag) {
tagService.updateTag(tag);
return "redirect:/admin/tag";
}
}

@ -0,0 +1,176 @@
package com.liuyanzhao.ssm.blog.controller.admin;
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;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author liuyanzhao
*/
@Controller
@RequestMapping("/admin/user")
public class BackUserController {
@Autowired
private UserService userService;
/**
*
*
* @return
*/
@RequestMapping(value = "")
public ModelAndView userList() {
ModelAndView modelandview = new ModelAndView();
List<User> userList = userService.listUser();
modelandview.addObject("userList", userList);
modelandview.setViewName("Admin/User/index");
return modelandview;
}
/**
*
*
* @return
*/
@RequestMapping(value = "/insert")
public ModelAndView insertUserView() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("Admin/User/insert");
return modelAndView;
}
/**
*
*
* @param request
* @return
*/
@RequestMapping(value = "/checkUserName", method = RequestMethod.POST, produces = {"text/plain;charset=UTF-8"})
@ResponseBody
public String checkUserName(HttpServletRequest request) {
Map<String, Object> map = new HashMap<String, Object>();
String username = request.getParameter("username");
User user = userService.getUserByName(username);
int id = Integer.valueOf(request.getParameter("id"));
//用户名已存在,但不是当前用户(编辑用户的时候,不提示)
if (user != null) {
if (user.getUserId() != id) {
map.put("code", 1);
map.put("msg", "用户名已存在!");
}
} else {
map.put("code", 0);
map.put("msg", "");
}
String result = new JSONObject(map).toString();
return result;
}
/**
* Email
*
* @param request
* @return
*/
@RequestMapping(value = "/checkUserEmail", method = RequestMethod.POST, produces = {"text/plain;charset=UTF-8"})
@ResponseBody
public String checkUserEmail(HttpServletRequest request) {
Map<String, Object> map = new HashMap<String, Object>();
String email = request.getParameter("email");
User user = userService.getUserByEmail(email);
int id = Integer.valueOf(request.getParameter("id"));
//用户名已存在,但不是当前用户(编辑用户的时候,不提示)
if (user != null) {
if (user.getUserId() != id) {
map.put("code", 1);
map.put("msg", "电子邮箱已存在!");
}
} else {
map.put("code", 0);
map.put("msg", "");
}
String result = new JSONObject(map).toString();
return result;
}
/**
*
*
* @param user
* @return
*/
@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) {
user.setUserRegisterTime(new Date());
user.setUserStatus(1);
user.setUserRole(UserRole.USER.getValue());
userService.insertUser(user);
}
return "redirect:/admin/user";
}
/**
*
*
* @param id
* @return
*/
@RequestMapping(value = "/delete/{id}")
public String deleteUser(@PathVariable("id") Integer id) {
userService.deleteUser(id);
return "redirect:/admin/user";
}
/**
*
*
* @param id
* @return
*/
@RequestMapping(value = "/edit/{id}")
public ModelAndView editUserView(@PathVariable("id") Integer id) {
ModelAndView modelAndView = new ModelAndView();
User user = userService.getUserById(id);
modelAndView.addObject("user", user);
modelAndView.setViewName("Admin/User/edit");
return modelAndView;
}
/**
*
*
* @param user
* @return
*/
@RequestMapping(value = "/editSubmit", method = RequestMethod.POST)
public String editUserSubmit(User user) {
userService.updateUser(user);
return "redirect:/admin/user";
}
}

@ -0,0 +1,93 @@
package com.liuyanzhao.ssm.blog.controller.admin;
import com.liuyanzhao.ssm.blog.dto.JsonResult;
import com.liuyanzhao.ssm.blog.dto.UploadFileVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
/**
* @author liuyanzhao
*/
@Slf4j
@RestController
@RequestMapping("/admin/upload")
public class UploadFileController {
/**
*
*/
// 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";
/**
*
*
* @param file
* @return
* @throws IOException
*/
@RequestMapping(value = "/img", method = RequestMethod.POST)
public JsonResult uploadFile(@RequestParam("file") MultipartFile file) {
//1.文件后缀过滤,只允许部分后缀
//文件的完整名称,如spring.jpeg
String filename = file.getOriginalFilename();
//文件名,如spring
String name = filename.substring(0, filename.indexOf("."));
//文件后缀,如.jpeg
String suffix = filename.substring(filename.lastIndexOf("."));
if (allowSuffix.indexOf(suffix) == -1) {
return new JsonResult().fail("不允许上传该后缀的文件!");
}
//2.创建文件目录
//创建年月文件夹
Calendar date = Calendar.getInstance();
File dateDirs = new File(date.get(Calendar.YEAR)
+ File.separator + (date.get(Calendar.MONTH) + 1));
//目标文件
File descFile = new File(rootPath + File.separator + dateDirs + File.separator + filename);
int i = 1;
//若文件存在重命名
String newFilename = filename;
while (descFile.exists()) {
newFilename = name + "(" + i + ")" + suffix;
String parentPath = descFile.getParent();
descFile = new File(parentPath + File.separator + newFilename);
i++;
}
//判断目标文件所在的目录是否存在
if (!descFile.getParentFile().exists()) {
//如果目标文件所在的目录不存在,则创建父目录
descFile.getParentFile().mkdirs();
}
//3.存储文件
//将内存中的数据写入磁盘
try {
file.transferTo(descFile);
} catch (Exception e) {
e.printStackTrace();
log.error("上传失败cause:{}", e);
}
//完整的url
String fileUrl = "/uploads/" + dateDirs + "/" + newFilename;
//4.返回URL
UploadFileVO uploadFileVO = new UploadFileVO();
uploadFileVO.setTitle(filename);
uploadFileVO.setSrc(fileUrl);
return new JsonResult().ok(uploadFileVO);
}
}

@ -0,0 +1,134 @@
package com.liuyanzhao.ssm.blog.controller.home;
import com.alibaba.fastjson.JSON;
import com.liuyanzhao.ssm.blog.enums.ArticleStatus;
import com.liuyanzhao.ssm.blog.entity.Article;
import com.liuyanzhao.ssm.blog.entity.Comment;
import com.liuyanzhao.ssm.blog.entity.Tag;
import com.liuyanzhao.ssm.blog.entity.User;
import com.liuyanzhao.ssm.blog.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* controller
*
* @author
* @date 2017/8/24
*/
@Controller
public class ArticleController {
@Autowired
private ArticleService articleService;
@Autowired
private CommentService commentService;
@Autowired
private UserService userService;
@Autowired
private TagService tagService;
@Autowired
private CategoryService categoryService;
/**
*
*
* @param articleId ID
* @return modelAndView
*/
@RequestMapping(value = "/article/{articleId}")
public String getArticleDetailPage(@PathVariable("articleId") Integer articleId, Model model) {
//文章信息,分类,标签,作者,评论
Article article = articleService.getArticleByStatusAndId(ArticleStatus.PUBLISH.getValue(), articleId);
if (article == null) {
return "Home/Error/404";
}
//用户信息
User user = userService.getUserById(article.getArticleUserId());
article.setUser(user);
//文章信息
model.addAttribute("article", article);
//评论列表
List<Comment> commentList = commentService.listCommentByArticleId(articleId);
model.addAttribute("commentList", commentList);
//相关文章
List<Integer> categoryIds = articleService.listCategoryIdByArticleId(articleId);
List<Article> similarArticleList = articleService.listArticleByCategoryIds(categoryIds, 5);
model.addAttribute("similarArticleList", similarArticleList);
//猜你喜欢
List<Article> mostViewArticleList = articleService.listArticleByViewCount(5);
model.addAttribute("mostViewArticleList", mostViewArticleList);
//获取下一篇文章
Article afterArticle = articleService.getAfterArticle(articleId);
model.addAttribute("afterArticle", afterArticle);
//获取上一篇文章
Article preArticle = articleService.getPreArticle(articleId);
model.addAttribute("preArticle", preArticle);
//侧边栏
//标签列表显示
List<Tag> allTagList = tagService.listTag();
model.addAttribute("allTagList", allTagList);
//获得随机文章
List<Article> randomArticleList = articleService.listRandomArticle(8);
model.addAttribute("randomArticleList", randomArticleList);
//获得热评文章
List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(8);
model.addAttribute("mostCommentArticleList", mostCommentArticleList);
return "Home/Page/articleDetail";
}
/**
*
*
* @param id ID
* @return
*/
@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);
Integer articleCount = article.getArticleLikeCount() + 1;
article.setArticleLikeCount(articleCount);
articleService.updateArticle(article);
return JSON.toJSONString(articleCount);
}
/**
* 访
*
* @param id ID
* @return 访
*/
@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);
Integer articleCount = article.getArticleViewCount() + 1;
article.setArticleViewCount(articleCount);
articleService.updateArticle(article);
return JSON.toJSONString(articleCount);
}
}

@ -0,0 +1,83 @@
package com.liuyanzhao.ssm.blog.controller.home;
import com.github.pagehelper.PageInfo;
import com.liuyanzhao.ssm.blog.enums.ArticleStatus;
import com.liuyanzhao.ssm.blog.entity.Article;
import com.liuyanzhao.ssm.blog.entity.Category;
import com.liuyanzhao.ssm.blog.entity.Tag;
import com.liuyanzhao.ssm.blog.service.ArticleService;
import com.liuyanzhao.ssm.blog.service.CategoryService;
import com.liuyanzhao.ssm.blog.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
/**
* controller
*
* @author
* @date 2017/8/24
*/
@Controller
public class CategoryController {
@Autowired
private CategoryService categoryService;
@Autowired
private ArticleService articleService;
@Autowired
private TagService tagService;
/**
*
*
* @param cateId ID
* @return
*/
@RequestMapping("/category/{cateId}")
public String getArticleListByCategory(@PathVariable("cateId") Integer cateId,
@RequestParam(required = false, defaultValue = "1") Integer pageIndex,
@RequestParam(required = false, defaultValue = "10") Integer pageSize,
Model model) {
//该分类信息
Category category = categoryService.getCategoryById(cateId);
if (category == null) {
return "redirect:/404";
}
model.addAttribute("category", category);
//文章列表
HashMap<String, Object> criteria = new HashMap<>(2);
criteria.put("categoryId", cateId);
criteria.put("status", ArticleStatus.PUBLISH.getValue());
PageInfo<Article> articlePageInfo = articleService.pageArticle(pageIndex, pageSize, criteria);
model.addAttribute("pageInfo", articlePageInfo);
//侧边栏
//标签列表显示
List<Tag> allTagList = tagService.listTag();
model.addAttribute("allTagList", allTagList);
//获得随机文章
List<Article> randomArticleList = articleService.listRandomArticle(8);
model.addAttribute("randomArticleList", randomArticleList);
//获得热评文章
List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(8);
model.addAttribute("mostCommentArticleList", mostCommentArticleList);
model.addAttribute("pageUrlPrefix", "/category/"+cateId+"?pageIndex");
return "Home/Page/articleListByCategory";
}
}

@ -0,0 +1,85 @@
package com.liuyanzhao.ssm.blog.controller.home;
import cn.hutool.http.HtmlUtil;
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;
import com.liuyanzhao.ssm.blog.service.CommentService;
import com.liuyanzhao.ssm.blog.util.MyUtils;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.Objects;
/**
* @author
* @date 2017/9/10
*/
@Controller
@RestController
public class CommentController {
@Autowired
private CommentService commentService;
@Autowired
private ArticleService articleService;
/**
*
*
* @param request
* @param comment
*/
@RequestMapping(value = "/comment", method = {RequestMethod.POST})
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 (Objects.equals(user.getUserId(), article.getArticleUserId())) {
comment.setCommentRole(Role.OWNER.getValue());
} else {
comment.setCommentRole(Role.VISITOR.getValue());
}
comment.setCommentAuthorAvatar(user.getUserAvatar());
//过滤字符防止XSS攻击
comment.setCommentContent(HtmlUtil.escape(comment.getCommentContent()));
comment.setCommentAuthorName(user.getUserNickname());
comment.setCommentAuthorEmail(user.getUserEmail());
comment.setCommentAuthorUrl(user.getUserUrl());
try {
commentService.insertComment(comment);
//更新文章的评论数
articleService.updateCommentCount(article.getArticleId());
} catch (Exception e) {
e.printStackTrace();
return new JsonResult().fail();
}
return new JsonResult().ok();
}
}

@ -0,0 +1,124 @@
package com.liuyanzhao.ssm.blog.controller.home;
import com.github.pagehelper.PageInfo;
import com.liuyanzhao.ssm.blog.entity.Link;
import com.liuyanzhao.ssm.blog.enums.ArticleStatus;
import com.liuyanzhao.ssm.blog.enums.LinkStatus;
import com.liuyanzhao.ssm.blog.enums.NoticeStatus;
import com.liuyanzhao.ssm.blog.entity.*;
import com.liuyanzhao.ssm.blog.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
/**
* controller
*
* @author
* @date 2017/8/24
*/
@Controller
public class IndexController {
@Autowired
private ArticleService articleService;
@Autowired
private LinkService linkService;
@Autowired
private NoticeService noticeService;
@Autowired
private TagService tagService;
@Autowired
private CommentService commentService;
@RequestMapping(value = {"/", "/article"})
public String index(@RequestParam(required = false, defaultValue = "1") Integer pageIndex,
@RequestParam(required = false, defaultValue = "10") Integer pageSize, Model model) {
HashMap<String, Object> criteria = new HashMap<>(1);
criteria.put("status", ArticleStatus.PUBLISH.getValue());
//文章列表
PageInfo<Article> articleList = articleService.pageArticle(pageIndex, pageSize, criteria);
model.addAttribute("pageInfo", articleList);
//公告
List<Notice> noticeList = noticeService.listNotice(NoticeStatus.NORMAL.getValue());
model.addAttribute("noticeList", noticeList);
//友情链接
List<Link> linkList = linkService.listLink(LinkStatus.NORMAL.getValue());
model.addAttribute("linkList", linkList);
//侧边栏显示
//标签列表显示
List<Tag> allTagList = tagService.listTag();
model.addAttribute("allTagList", allTagList);
//最新评论
List<Comment> recentCommentList = commentService.listRecentComment(null, 10);
model.addAttribute("recentCommentList", recentCommentList);
model.addAttribute("pageUrlPrefix", "/article?pageIndex");
return "Home/index";
}
@RequestMapping(value = "/search")
public String search(
@RequestParam("keywords") String keywords,
@RequestParam(required = false, defaultValue = "1") Integer pageIndex,
@RequestParam(required = false, defaultValue = "10") Integer pageSize, Model model) {
//文章列表
HashMap<String, Object> criteria = new HashMap<>(2);
criteria.put("status", ArticleStatus.PUBLISH.getValue());
criteria.put("keywords", keywords);
PageInfo<Article> articlePageInfo = articleService.pageArticle(pageIndex, pageSize, criteria);
model.addAttribute("pageInfo", articlePageInfo);
//侧边栏显示
//标签列表显示
List<Tag> allTagList = tagService.listTag();
model.addAttribute("allTagList", allTagList);
//获得随机文章
List<Article> randomArticleList = articleService.listRandomArticle(8);
model.addAttribute("randomArticleList", randomArticleList);
//获得热评文章
List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(8);
model.addAttribute("mostCommentArticleList", mostCommentArticleList);
//最新评论
List<Comment> recentCommentList = commentService.listRecentComment(null, 10);
model.addAttribute("recentCommentList", recentCommentList);
model.addAttribute("pageUrlPrefix", "/search?keywords=" + keywords + "&pageIndex");
return "Home/Page/search";
}
@RequestMapping("/404")
public String NotFound(@RequestParam(required = false) String message, Model model) {
model.addAttribute("message", message);
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);
return "Home/Error/500";
}
}

@ -0,0 +1,49 @@
package com.liuyanzhao.ssm.blog.controller.home;
import com.liuyanzhao.ssm.blog.entity.Article;
import com.liuyanzhao.ssm.blog.entity.Link;
import com.liuyanzhao.ssm.blog.enums.LinkStatus;
import com.liuyanzhao.ssm.blog.service.ArticleService;
import com.liuyanzhao.ssm.blog.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Date;
import java.util.List;
/**
*
* @author
* @date 2017/9/5
*/
@Controller
public class LinkController {
@Autowired
private LinkService linkService;
@Autowired
private ArticleService articleService;
@RequestMapping("/applyLink")
public String applyLinkView(Model model) {
//侧边栏显示
//获得热评文章
List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(8);
model.addAttribute("mostCommentArticleList", mostCommentArticleList);
return "Home/Page/applyLink";
}
@RequestMapping(value = "/applyLinkSubmit",method = {RequestMethod.POST}, produces = {"text/plain;charset=UTF-8"})
@ResponseBody
public void applyLinkSubmit(Link link) {
link.setLinkStatus(LinkStatus.HIDDEN.getValue());
link.setLinkCreateTime(new Date());
link.setLinkUpdateTime(new Date());
linkService.insertLink(link);
}
}

@ -0,0 +1,46 @@
package com.liuyanzhao.ssm.blog.controller.home;
import com.liuyanzhao.ssm.blog.entity.Article;
import com.liuyanzhao.ssm.blog.entity.Notice;
import com.liuyanzhao.ssm.blog.service.ArticleService;
import com.liuyanzhao.ssm.blog.service.NoticeService;
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 java.util.List;
/**
* @author liuyanzhao
*/
@Controller
public class NoticeController {
@Autowired
private NoticeService noticeService;
@Autowired
private ArticleService articleService;
/**
*
*
* @param noticeId
* @return
*/
@RequestMapping(value = "/notice/{noticeId}")
public String NoticeDetailView(@PathVariable("noticeId") Integer noticeId,
Model model) {
//公告内容和信息显示
Notice notice = noticeService.getNoticeById(noticeId);
model.addAttribute("notice",notice);
//侧边栏显示
//获得热评文章
List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(8);
model.addAttribute("mostCommentArticleList", mostCommentArticleList);
return "Home/Page/noticeDetail";
}
}

@ -0,0 +1,119 @@
package com.liuyanzhao.ssm.blog.controller.home;
import com.liuyanzhao.ssm.blog.entity.Article;
import com.liuyanzhao.ssm.blog.entity.Category;
import com.liuyanzhao.ssm.blog.entity.Page;
import com.liuyanzhao.ssm.blog.entity.Tag;
import com.liuyanzhao.ssm.blog.service.ArticleService;
import com.liuyanzhao.ssm.blog.service.CategoryService;
import com.liuyanzhao.ssm.blog.service.PageService;
import com.liuyanzhao.ssm.blog.service.TagService;
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 java.util.List;
/**
* @author
* @date 2017/9/7
*/
@Controller
public class PageController {
@Autowired
private PageService pageService;
@Autowired
private ArticleService articleService;
@Autowired
private CategoryService categoryService;
@Autowired
private TagService tagService;
/**
*
*
* @param key
* @return
*/
@RequestMapping(value = "/{key}")
public String pageDetail(@PathVariable("key") String key, Model model) {
Page page = pageService.getPageByKey(1, key);
if (page == null) {
return "redirect:/404";
}
model.addAttribute("page", page);
//侧边栏显示
//获得热评文章
List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(8);
model.addAttribute("mostCommentArticleList", mostCommentArticleList);
return "Home/Page/page";
}
/**
*
*
* @return
*/
@RequestMapping(value = "/articleFile")
public String articleFile(Model model) {
List<Article> articleList = articleService.listAllNotWithContent();
model.addAttribute("articleList", articleList);
//侧边栏显示
//获得热评文章
List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(10);
model.addAttribute("mostCommentArticleList", mostCommentArticleList);
return "Home/Page/articleFile";
}
/**
*
*
* @return
*/
@RequestMapping(value = "/map")
public String siteMap(Model model) {
//文章显示
List<Article> articleList = articleService.listAllNotWithContent();
model.addAttribute("articleList", articleList);
//分类显示
List<Category> categoryList = categoryService.listCategory();
model.addAttribute("categoryList", categoryList);
//标签显示
List<Tag> tagList = tagService.listTag();
model.addAttribute("tagList", tagList);
//侧边栏显示
//获得热评文章
List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(10);
model.addAttribute("mostCommentArticleList", mostCommentArticleList);
return "Home/Page/siteMap";
}
/**
*
*
* @return
*/
@RequestMapping(value = "/message")
public String message(Model model) {
//侧边栏显示
//获得热评文章
List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(8);
model.addAttribute("mostCommentArticleList", mostCommentArticleList);
return "Home/Page/message";
}
}

@ -0,0 +1,72 @@
package com.liuyanzhao.ssm.blog.controller.home;
import com.github.pagehelper.PageInfo;
import com.liuyanzhao.ssm.blog.entity.Article;
import com.liuyanzhao.ssm.blog.entity.Tag;
import com.liuyanzhao.ssm.blog.enums.ArticleStatus;
import com.liuyanzhao.ssm.blog.service.ArticleService;
import com.liuyanzhao.ssm.blog.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
/**
* @author
* @date 2017/9/2
*/
@Controller
public class TagController {
@Autowired
private TagService tagService;
@Autowired
private ArticleService articleService;
/**
*
*
* @param tagId ID
* @return
*/
@RequestMapping("/tag/{tagId}")
public String getArticleListByTag(@PathVariable("tagId") Integer tagId,
@RequestParam(required = false, defaultValue = "1") Integer pageIndex,
@RequestParam(required = false, defaultValue = "10") Integer pageSize,
Model model) {
//该标签信息
Tag tag = tagService.getTagById(tagId);
if (tag == null) {
return "redirect:/404";
}
model.addAttribute("tag", tag);
//文章列表
HashMap<String, Object> criteria = new HashMap<>(2);
criteria.put("tagId", tagId);
criteria.put("status", ArticleStatus.PUBLISH.getValue());
PageInfo<Article> articlePageInfo = articleService.pageArticle(pageIndex, pageSize, criteria);
model.addAttribute("pageInfo", articlePageInfo);
//侧边栏
//标签列表显示
List<Tag> allTagList = tagService.listTag();
model.addAttribute("allTagList", allTagList);
//获得随机文章
List<Article> randomArticleList = articleService.listRandomArticle(8);
model.addAttribute("randomArticleList", randomArticleList);
//获得热评文章
List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(8);
model.addAttribute("mostCommentArticleList", mostCommentArticleList);
model.addAttribute("pageUrlPrefix", "/tag/"+tagId+"?pageIndex");
return "Home/Page/articleListByTag";
}
}

@ -0,0 +1,32 @@
package com.liuyanzhao.ssm.blog.dto;
import lombok.Data;
import java.util.List;
/**
* @author
* @date 2018/11/25 3:56
*/
@Data
public class ArticleParam {
private Integer articleId;
private String articleTitle;
private String articleContent;
private Integer articleParentCategoryId;
private Integer articleChildCategoryId;
private Integer articleOrder;
private Integer articleStatus;
private String articleThumbnail;
private List<Integer> articleTagIds;
}

@ -0,0 +1,56 @@
package com.liuyanzhao.ssm.blog.dto;
import lombok.Data;
/**
* @author
* @date 2017/11/30 7:04
*/
@Data
public class JsonResult<T> {
/**
*
*/
private Integer code;
/**
*
*/
private String msg;
/**
*
*/
private T data;
public JsonResult(Integer code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public JsonResult() {
}
public JsonResult fail() {
return new JsonResult(1, "操作失败", null);
}
public JsonResult fail(String msg) {
return new JsonResult(1, msg, null);
}
public JsonResult ok() {
return new JsonResult(0, "操作成功", null);
}
public JsonResult ok(T data) {
return new JsonResult(0, "操作成功", data);
}
}

@ -0,0 +1,37 @@
package com.liuyanzhao.ssm.blog.dto;
import lombok.Data;
/**
* @author
* @date 2017/11/30 7:04
*/
@Data
public class ResultVO<T> {
/**
*
*/
private Integer code;
/**
*
*/
private String msg;
/**
*
*/
private T data;
public ResultVO(Integer code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public ResultVO() {
}
}

@ -0,0 +1,17 @@
package com.liuyanzhao.ssm.blog.dto;
import lombok.Data;
/**
* @author
* @date 2017/11/30 7:41
*/
@Data
public class UploadFileVO {
private String src;
private String title;
}

@ -0,0 +1,52 @@
package com.liuyanzhao.ssm.blog.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* @author liuyanzhao
* Article Java Serializable
*/
@Data
public class Article implements Serializable{
private static final long serialVersionUID = 5207865247400761539L;
private Integer articleId;
private Integer articleUserId;
private String articleTitle;
private Integer articleViewCount;
private Integer articleCommentCount;
private Integer articleLikeCount;
private Date articleCreateTime;
private Date articleUpdateTime;
private Integer articleIsComment;
private Integer articleStatus;
private Integer articleOrder;
private String articleContent;
private String articleSummary;
private String articleThumbnail;
private User user;
private List<Tag> tagList;
private List<Category> categoryList;
}

@ -0,0 +1,28 @@
package com.liuyanzhao.ssm.blog.entity;
import lombok.Data;
import java.io.Serializable;
/**
*
*
* @author liuyanzhao
*/
@Data
public class ArticleCategoryRef implements Serializable{
private static final long serialVersionUID = -6809206515467725995L;
private Integer articleId;
private Integer categoryId;
public ArticleCategoryRef() {
}
public ArticleCategoryRef(Integer articleId, Integer categoryId) {
this.articleId = articleId;
this.categoryId = categoryId;
}
}

@ -0,0 +1,28 @@
package com.liuyanzhao.ssm.blog.entity;
import lombok.Data;
import java.io.Serializable;
/**
*
*
* @author
* @date 2018/11/17 5:20
*/
@Data
public class ArticleTagRef implements Serializable {
private static final long serialVersionUID = -5816783232020910492L;
private Integer articleId;
private Integer tagId;
public ArticleTagRef() {
}
public ArticleTagRef(Integer articleId, Integer tagId) {
this.articleId = articleId;
this.tagId = tagId;
}
}

@ -0,0 +1,64 @@
package com.liuyanzhao.ssm.blog.entity;
import lombok.Data;
import java.io.Serializable;
/**
* @author liuyanzhao
*/
@Data
public class Category implements Serializable {
private static final long serialVersionUID = 6687286913317513141L;
private Integer categoryId;
private Integer categoryPid;
private String categoryName;
private String categoryDescription;
private Integer categoryOrder;
private String categoryIcon;
/**
* ()
*/
private Integer articleCount;
public Category(Integer categoryId, Integer categoryPid, String categoryName, String categoryDescription, Integer categoryOrder, String categoryIcon,Integer articleCount) {
this.categoryId = categoryId;
this.categoryPid = categoryPid;
this.categoryName = categoryName;
this.categoryDescription = categoryDescription;
this.categoryOrder = categoryOrder;
this.categoryIcon = categoryIcon;
this.articleCount = articleCount;
}
public Category(Integer categoryId, String categoryName) {
this.categoryId = categoryId;
this.categoryName = categoryName;
}
public Category(Integer categoryId) {
this.categoryId = categoryId;
}
public Category() {}
/**
*
*
* @return
*/
public static Category Default() {
return new Category(100000000, "未分类");
}
}

@ -0,0 +1,55 @@
package com.liuyanzhao.ssm.blog.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
*
*
* @author liuyanzhao
*/
@Data
public class Comment implements Serializable {
private static final long serialVersionUID = -1038897351672911219L;
private Integer commentId;
private Integer commentPid;
private String commentPname;
private Integer commentArticleId;
private String commentAuthorName;
private String commentAuthorEmail;
private String commentAuthorUrl;
private String commentAuthorAvatar;
private String commentContent;
private String commentAgent;
private String commentIp;
private Date commentCreateTime;
/**
* (1访0)
*/
private Integer commentRole;
/**
* ID
*/
private Integer commentUserId;
/**
*
*/
private Article article;
}

@ -0,0 +1,39 @@
package com.liuyanzhao.ssm.blog.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @author liuyanzhao
*/
@Data
public class Link implements Serializable{
private static final long serialVersionUID = -259829372268790508L;
private Integer linkId;
private String linkUrl;
private String linkName;
private String linkImage;
private String linkDescription;
private String linkOwnerNickname;
private String linkOwnerContact;
private Date linkUpdateTime;
private Date linkCreateTime;
private Integer linkOrder;
private Integer linkStatus;
}

@ -0,0 +1,25 @@
package com.liuyanzhao.ssm.blog.entity;
import lombok.Data;
import java.io.Serializable;
/**
* @author liuyanzhao
*/
@Data
public class Menu implements Serializable {
private static final long serialVersionUID = 489914127235951698L;
private Integer menuId;
private String menuName;
private String menuUrl;
private Integer menuLevel;
private String menuIcon;
private Integer menuOrder;
}

@ -0,0 +1,28 @@
package com.liuyanzhao.ssm.blog.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @author liuyanzhao
*/
@Data
public class Notice implements Serializable{
private static final long serialVersionUID = -4901560494243593100L;
private Integer noticeId;
private String noticeTitle;
private String noticeContent;
private Date noticeCreateTime;
private Date noticeUpdateTime;
private Integer noticeStatus;
private Integer noticeOrder;
}

@ -0,0 +1,41 @@
package com.liuyanzhao.ssm.blog.entity;
import lombok.Data;
import java.io.Serializable;
/**
* @author liuyanzhao
*/
@Data
public class Options implements Serializable{
private static final long serialVersionUID = -776792869602511933L;
private Integer optionId;
private String optionSiteTitle;
private String optionSiteDescrption;
private String optionMetaDescrption;
private String optionMetaKeyword;
private String optionAboutsiteAvatar;
private String optionAboutsiteTitle;
private String optionAboutsiteContent;
private String optionAboutsiteWechat;
private String optionAboutsiteQq;
private String optionAboutsiteGithub;
private String optionAboutsiteWeibo;
private String optionTongji;
private Integer optionStatus;
}

@ -0,0 +1,33 @@
package com.liuyanzhao.ssm.blog.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @author liuyanzhao
*/
@Data
public class Page implements Serializable{
private static final long serialVersionUID = 3927496662110298634L;
private Integer pageId;
private String pageKey;
private String pageTitle;
private String pageContent;
private Date pageCreateTime;
private Date pageUpdateTime;
private Integer pageViewCount;
private Integer pageCommentCount;
private Integer pageStatus;
}

@ -0,0 +1,37 @@
package com.liuyanzhao.ssm.blog.entity;
import lombok.Data;
import java.io.Serializable;
/**
* @author liuyanzhao
*/
@Data
public class Tag implements Serializable{
private static final long serialVersionUID = 605449151900057035L;
private Integer tagId;
private String tagName;
private String tagDescription;
/**
* ()
*/
private Integer articleCount;
public Tag() {
}
public Tag(Integer tagId) {
this.tagId = tagId;
}
public Tag(Integer tagId, String tagName, String tagDescription, Integer articleCount) {
this.tagId = tagId;
this.tagName = tagName;
this.tagDescription = tagDescription;
this.articleCount = articleCount;
}
}

@ -0,0 +1,46 @@
package com.liuyanzhao.ssm.blog.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @author liuyanzhao
*/
@Data
public class User implements Serializable{
private static final long serialVersionUID = -4415517704211731385L;
private Integer userId;
private String userName;
private String userPass;
private String userNickname;
private String userEmail;
private String userUrl;
private String userAvatar;
private String userLastLoginIp;
private Date userRegisterTime;
private Date userLastLoginTime;
private Integer userStatus;
/**
* admin/user
*/
private String userRole;
/**
*
*/
private Integer articleCount;
}

@ -0,0 +1,37 @@
package com.liuyanzhao.ssm.blog.enums;
/**
* @author
* @date 2018/11/17 4:47
*/
public enum ArticleCommentStatus {
ALLOW(1, "允许"),
NOT_ALLOW(0, "不允许");
private Integer value;
private String message;
ArticleCommentStatus(Integer value, String message) {
this.value = value;
this.message = message;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,37 @@
package com.liuyanzhao.ssm.blog.enums;
/**
* @author
* @date 2018/11/17 4:47
*/
public enum ArticleStatus {
PUBLISH(1, "已发布"),
DRAFT(0, "草稿");
private Integer value;
private String message;
ArticleStatus(Integer value, String message) {
this.value = value;
this.message = message;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,39 @@
package com.liuyanzhao.ssm.blog.enums;
import lombok.Data;
/**
* @author
* @date 2018/11/17 4:47
*/
public enum CategoryStatus {
NORMAL(1, "正常"),
HIDDEN(0, "隐藏");
private Integer value;
private String message;
CategoryStatus(Integer value, String message) {
this.value = value;
this.message = message;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,37 @@
package com.liuyanzhao.ssm.blog.enums;
/**
* @author
* @date 2018/11/17 4:47
*/
public enum LinkStatus {
NORMAL(1, "显示"),
HIDDEN(0, "隐藏");
private Integer value;
private String message;
LinkStatus(Integer value, String message) {
this.value = value;
this.message = message;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,37 @@
package com.liuyanzhao.ssm.blog.enums;
/**
* @author
* @date 2018/11/17 4:47
*/
public enum MenuLevel {
TOP_MENU(1, "顶部菜单"),
MAIN_MENU(2, "主体菜单");
private Integer value;
private String message;
MenuLevel(Integer value, String message) {
this.value = value;
this.message = message;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,37 @@
package com.liuyanzhao.ssm.blog.enums;
/**
* @author
* @date 2018/11/17 4:47
*/
public enum NoticeStatus {
NORMAL(1, "显示"),
HIDDEN(0, "隐藏");
private Integer value;
private String message;
NoticeStatus(Integer value, String message) {
this.value = value;
this.message = message;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,37 @@
package com.liuyanzhao.ssm.blog.enums;
/**
* @author
* @date 2018/11/17 4:47
*/
public enum PageStatus {
NORMAL(1, "显示"),
HIDDEN(0, "隐藏");
private Integer value;
private String message;
PageStatus(Integer value, String message) {
this.value = value;
this.message = message;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,37 @@
package com.liuyanzhao.ssm.blog.enums;
/**
* @author
* @date 2018/11/17 4:47
*/
public enum Role {
OWNER(1, "博主"),
VISITOR(0, "其他用户");
private Integer value;
private String message;
Role(Integer value, String message) {
this.value = value;
this.message = message;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -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;
}
}

@ -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) {
}
}

@ -0,0 +1,87 @@
package com.liuyanzhao.ssm.blog.interceptor;
import com.liuyanzhao.ssm.blog.entity.Article;
import com.liuyanzhao.ssm.blog.entity.Options;
import com.liuyanzhao.ssm.blog.enums.ArticleStatus;
import com.liuyanzhao.ssm.blog.enums.LinkStatus;
import com.liuyanzhao.ssm.blog.entity.Category;
import com.liuyanzhao.ssm.blog.entity.Menu;
import com.liuyanzhao.ssm.blog.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* @author liuyanzhao
*/
@Component
public class HomeResourceInterceptor implements HandlerInterceptor {
@Autowired
private ArticleService articleService;
@Autowired
private CategoryService categoryService;
@Autowired
private TagService tagService;
@Autowired
private LinkService linkService;
@Autowired
private OptionsService optionsService;
@Autowired
private MenuService menuService;
/**
* WebRequest
*/
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws IOException {
// 菜单显示
List<Menu> menuList = menuService.listMenu();
request.setAttribute("menuList", menuList);
List<Category> categoryList = categoryService.listCategory();
request.setAttribute("allCategoryList", categoryList);
//获得网站概况
List<String> siteBasicStatistics = new ArrayList<String>();
siteBasicStatistics.add(articleService.countArticle(ArticleStatus.PUBLISH.getValue()) + "");
siteBasicStatistics.add(articleService.countArticleComment() + "");
siteBasicStatistics.add(categoryService.countCategory() + "");
siteBasicStatistics.add(tagService.countTag() + "");
siteBasicStatistics.add(linkService.countLink(LinkStatus.NORMAL.getValue()) + "");
siteBasicStatistics.add(articleService.countArticleView() + "");
request.setAttribute("siteBasicStatistics", siteBasicStatistics);
//最后更新的文章
Article lastUpdateArticle = articleService.getLastUpdateArticle();
request.setAttribute("lastUpdateArticle", lastUpdateArticle);
//页脚显示
//博客基本信息显示(Options)
Options options = optionsService.getOptions();
request.setAttribute("options", options);
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) {
}
}

@ -0,0 +1,39 @@
package com.liuyanzhao.ssm.blog.interceptor;
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;
/**
* @author liuyanzhao
*/
@Component
public class LoginInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws IOException {
//这里可以根据session的用户来判断角色的权限根据权限来转发不同的页面
if(request.getSession().getAttribute("user") == null) {
response.sendRedirect("/login");
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) {
}
}

@ -0,0 +1,70 @@
package com.liuyanzhao.ssm.blog.mapper;
import com.liuyanzhao.ssm.blog.entity.ArticleCategoryRef;
import com.liuyanzhao.ssm.blog.entity.Category;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* Mapper
* @author liuyanzhao
*/
@Mapper
public interface ArticleCategoryRefMapper {
/**
*
* @param record
* @return
*/
int insert(ArticleCategoryRef record);
/**
* ID
* @param categoryId ID
* @return
*/
int deleteByCategoryId(Integer categoryId);
/**
* ID
* @param articleId ID
* @return
*/
int deleteByArticleId(Integer articleId);
/**
* ID
* @param categoryId ID
* @return
*/
int countArticleByCategoryId(Integer categoryId);
/**
* IDID
*
* @param articleId ID
* @return ID
*/
List<Integer> selectCategoryIdByArticleId(Integer articleId);
/**
* IDID
*
* @param categoryId ID
* @return ID
*/
List<Integer> selectArticleIdByCategoryId(Integer categoryId);
/**
* ID
*
* @param articleId ID
* @return
*/
List<Category> listCategoryByArticleId(Integer articleId);
}

@ -0,0 +1,223 @@
package com.liuyanzhao.ssm.blog.mapper;
import com.liuyanzhao.ssm.blog.entity.Article;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.HashMap;
import java.util.List;
/**
* Mapper
*
* @author liuyanzhao
*/
@Mapper
public interface ArticleMapper {
/**
* ID
*
* @param articleId ID
* @return
*/
Integer deleteById(Integer articleId);
/**
* ID
*
* @param userId ID
* @return
*/
Integer deleteByUserId(Integer userId);
/**
*
*
* @param article
* @return
*/
Integer insert(Article article);
/**
*
*
* @param article
* @return
*/
Integer update(Article article);
/**
*
*
* @param criteria
* @return
*/
List<Article> findAll(HashMap<String, Object> criteria);
/**
*
*
* @return
*/
List<Article> listAllNotWithContent();
/**
*
*
* @param status
* @return
*/
Integer countArticle(@Param(value = "status") Integer status);
/**
*
*
* @return
*/
Integer countArticleComment();
/**
*
*
* @return
*/
Integer countArticleView();
/**
* ()
*
* @return
*/
List<Article> listArticle();
/**
* id
*
* @param status
* @param id ID
* @return
*/
Article getArticleByStatusAndId(@Param(value = "status") Integer status, @Param(value = "id") Integer id);
/**
*
*
* @param status
* @param pageIndex
* @param pageSize
* @return
*/
@Deprecated
List<Article> pageArticle(@Param(value = "status") Integer status,
@Param(value = "pageIndex") Integer pageIndex,
@Param(value = "pageSize") Integer pageSize);
/**
* 访()
*
* @param limit
* @return
*/
List<Article> listArticleByViewCount(@Param(value = "limit") Integer limit);
/**
*
*
* @param id ID
* @return
*/
Article getAfterArticle(@Param(value = "id") Integer id);
/**
*
*
* @param id ID
* @return
*/
Article getPreArticle(@Param(value = "id") Integer id);
/**
*
*
* @param limit
* @return
*/
List<Article> listRandomArticle(@Param(value = "limit") Integer limit);
/**
*
*
* @param limit
* @return
*/
List<Article> listArticleByCommentCount(@Param(value = "limit") Integer limit);
/**
*
*
* @param articleId ID
*/
void updateCommentCount(@Param(value = "articleId") Integer articleId);
/**
*
*
* @return
*/
Article getLastUpdateArticle();
/**
*
*
* @param id ID
* @return
*/
Integer countArticleByUser(@Param(value = "id") Integer id);
/**
* ID
*
* @param categoryId ID
* @param limit
* @return
*/
List<Article> findArticleByCategoryId(@Param("categoryId") Integer categoryId,
@Param("limit") Integer limit);
/**
* ID
*
* @param categoryIds ID
* @param limit
* @return
*/
List<Article> findArticleByCategoryIds(@Param("categoryIds") List<Integer> categoryIds,
@Param("limit") Integer limit);
/**
*
*
* @param limit
* @return
*/
List<Article> listArticleByLimit(@Param("userId") Integer userId, @Param("limit") Integer limit);
/**
*
*
* @param ids Id
* @return
*/
Integer deleteBatch(@Param("ids") List<Integer> ids);
/**
* id
*
* @param userId
* @return
*/
List<Integer> listArticleIdsByUserId(Integer userId);
}

@ -0,0 +1,54 @@
package com.liuyanzhao.ssm.blog.mapper;
import com.liuyanzhao.ssm.blog.entity.ArticleTagRef;
import com.liuyanzhao.ssm.blog.entity.Tag;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* Mapper
* @author liuyanzhao
*/
@Mapper
public interface ArticleTagRefMapper {
/**
*
* @param record
* @return
*/
int insert(ArticleTagRef record);
/**
* ID
* @param tagId ID
* @return
*/
int deleteByTagId(Integer tagId);
/**
* ID
* @param articleId ID
* @return
*/
int deleteByArticleId(Integer articleId);
/**
* ID
* @param tagId ID
* @return
*/
int countArticleByTagId(Integer tagId);
/**
*
*
* @param articleId ID
* @return
*/
List<Tag> listTagByArticleId(Integer articleId);
}

@ -0,0 +1,79 @@
package com.liuyanzhao.ssm.blog.mapper;
import com.liuyanzhao.ssm.blog.entity.Category;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author liuyanzhao
*/
@Mapper
public interface CategoryMapper {
/**
*
*
* @param category
* @return
*/
int insert(Category category);
/**
*
*
* @param category
* @return
*/
int update(Category category);
/**
* id
*
* @param id ID
* @return
*/
Category getCategoryById(Integer id);
/**
*
*
* @param id ID
*/
int deleteCategory(Integer id);
/**
*
*
* @return
*/
Integer countCategory();
/**
*
*
* @return
*/
List<Category> listCategory();
/**
*
*
* @param id ID
* @return
*/
List<Category> findChildCategory(@Param(value = "id") Integer id);
/**
*
*
* @param name
* @return
*/
Category getCategoryByName(String name);
}

@ -0,0 +1,111 @@
package com.liuyanzhao.ssm.blog.mapper;
import com.liuyanzhao.ssm.blog.entity.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.HashMap;
import java.util.List;
@Mapper
public interface CommentMapper {
/**
* ID
*
* @param commentId ID
* @return
*/
int deleteById(Integer commentId);
/**
*
*
* @param comment
* @return
*/
int insert(Comment comment);
/**
* ID
*
* @param commentId ID
* @return
*/
Comment getCommentById(Integer commentId);
/**
*
*
* @param comment
* @return
*/
int update(Comment comment);
/**
* id
*
* @param id ID
* @return
*/
List<Comment> listCommentByArticleId(@Param(value = "id") Integer id);
/**
*
*
* @return
*/
List<Comment> listComment(HashMap<String, Object> criteria);
/**
*
*
* @return
*/
List<Comment> getReceiveComment(List<Integer> articleIds);
/**
*
*
* @return
*/
Integer countComment();
/**
*
*
* @param limit
* @return
*/
List<Comment> listRecentComment(@Param(value = "userId") Integer userId,
@Param(value = "limit") Integer limit);
/**
*
*
* @param id ID
* @return
*/
List<Comment> listChildComment(@Param(value = "id") Integer id);
/**
* ID
*
* @param userId ID
* @return
*/
Integer deleteByUserId(Integer userId);
/**
* ID
*
* @param articleId ID
* @return
*/
Integer deleteByArticleId(Integer articleId);
}

@ -0,0 +1,61 @@
package com.liuyanzhao.ssm.blog.mapper;
import com.liuyanzhao.ssm.blog.entity.Link;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author liuyanzhao
*/
@Mapper
public interface LinkMapper {
/**
*
* @param linkId ID
* @return
*/
int deleteById(Integer linkId);
/**
*
*
* @param link
* @return
*/
int insert(Link link);
/**
* ID
*
* @param linkId ID
* @return
*/
Link getLinkById(Integer linkId);
/**
*
*
* @param link ID
* @return
*/
int update(Link link);
/**
*
*
* @param status
* @return
*/
Integer countLink(@Param(value = "status") Integer status);
/**
*
*
* @param status
* @return
*/
List<Link> listLink(@Param(value = "status") Integer status);
}

@ -0,0 +1,49 @@
package com.liuyanzhao.ssm.blog.mapper;
import com.liuyanzhao.ssm.blog.entity.Menu;
import java.util.List;
/**
* @author liuyanzhao
*/
public interface MenuMapper {
/**
*
*
* @param menuId ID
* @return
*/
int deleteById(Integer menuId);
/**
*
* @param menu
* @return
*/
int insert(Menu menu);
/**
* ID
*
* @param menuId ID
* @return
*/
Menu getMenuById(Integer menuId);
/**
*
*
* @param menu
* @return
*/
int update(Menu menu);
/**
*
*
* @return
*/
List<Menu> listMenu() ;
}

@ -0,0 +1,70 @@
package com.liuyanzhao.ssm.blog.mapper;
import com.liuyanzhao.ssm.blog.entity.Notice;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author liuyanzhao
*/
@Mapper
public interface NoticeMapper {
/**
* ID
*
* @param noticeId ID
* @return
*/
int deleteById(Integer noticeId);
/**
*
*
* @param notice
* @return
*/
int insert(Notice notice);
/**
* ID
*
* @param noticeId ID
* @return
*/
Notice getNoticeById(Integer noticeId);
/**
*
*
* @param notice
* @return
*/
int update(Notice notice);
/**
*
*
* @param notice
* @return
*/
int updateByPrimaryKey(Notice notice);
/**
*
*
* @param status
* @return
*/
Integer countNotice(@Param(value = "status") Integer status);
/**
*
*
* @param status
* @return
*/
List<Notice> listNotice(@Param(value = "status") Integer status);
}

@ -0,0 +1,48 @@
package com.liuyanzhao.ssm.blog.mapper;
import com.liuyanzhao.ssm.blog.entity.Options;
import org.apache.ibatis.annotations.Mapper;
/**
* @author liuyanzhao
*/
@Mapper
public interface OptionsMapper {
/**
* ID
* @param optionId ID
* @return
*/
int deleteById(Integer optionId);
/**
*
* @param options
* @return
*/
int insert(Options options);
/**
* ID
*
* @param optionId ID
* @return
*/
Options getOptionsById(Integer optionId);
/**
*
*
* @param options
* @return
*/
int update(Options options);
/**
*
*
* @return
*/
Options getOptions();
}

@ -0,0 +1,63 @@
package com.liuyanzhao.ssm.blog.mapper;
import com.liuyanzhao.ssm.blog.entity.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author liuyanzhao
*/
@Mapper
public interface PageMapper {
/**
* ID
*
* @param pageId ID
* @return
*/
int deleteById(Integer pageId);
/**
*
*
* @param page
* @return
*/
int insert(Page page);
/**
* ID
*
* @param pageId ID
* @return
*/
Page getPageById(Integer pageId);
/**
*
*
* @param page
* @return
*/
int update(Page page);
/**
*
*
* @param status
* @return
*/
List<Page> listPage(@Param(value = "status") Integer status);
/**
* key
*
* @param status
* @param key
* @return
*/
Page getPageByKey(@Param(value = "status") Integer status,
@Param(value = "key") String key);
}

@ -0,0 +1,67 @@
package com.liuyanzhao.ssm.blog.mapper;
import com.liuyanzhao.ssm.blog.entity.Tag;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @author liuyanzhao
*/
@Mapper
public interface TagMapper {
/**
* ID
*
* @param tagId ID
* @return
*/
int deleteById(Integer tagId);
/**
*
*
* @param tag
* @return
*/
int insert(Tag tag);
/**
* ID
*
* @param tagId ID
* @return
*/
Tag getTagById(Integer tagId);
/**
*
* @param tag
* @return
*/
int update(Tag tag);
/**
*
*
* @return
*/
Integer countTag() ;
/**
*
*
* @return
*/
List<Tag> listTag() ;
/**
*
*
* @param name
* @return
*/
Tag getTagByName(String name) ;
}

@ -0,0 +1,79 @@
package com.liuyanzhao.ssm.blog.mapper;
import com.liuyanzhao.ssm.blog.entity.User;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @author liuyanzhao
*/
@Mapper
public interface UserMapper {
/**
* ID
*
* @param userId ID
* @return
*/
int deleteById(Integer userId);
/**
*
*
* @param user
* @return
*/
int insert(User user);
/**
* ID
*
* @param userId ID
* @return
*/
User getUserById(Integer userId);
/**
*
*
* @param user
* @return
*/
int update(User user);
/**
*
*
* @return
*/
List<User> listUser() ;
/**
* Email
*
* @param str Email
* @return
*/
User getUserByNameOrEmail(String str) ;
/**
*
*
* @param name
* @return
*/
User getUserByName(String name) ;
/**
* Email
*
* @param email
* @return
*/
User getUserByEmail(String email) ;
}

@ -0,0 +1,286 @@
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 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;
import java.util.HashMap;
import java.util.List;
/**
* Servie
*
* @author
* @date 2017/8/24
*/
@Service
@Slf4j
public class ArticleServiceImpl implements ArticleService {
@Autowired
private ArticleMapper articleMapper;
@Autowired
private ArticleCategoryRefMapper articleCategoryRefMapper;
@Autowired
private ArticleTagRefMapper articleTagRefMapper;
@Autowired
private UserMapper userMapper;
@Autowired
private CommentMapper commentMapper;
@Override
public Integer countArticle(Integer status) {
Integer count = 0;
try {
count = articleMapper.countArticle(status);
} catch (Exception e) {
e.printStackTrace();
log.error("根据状态统计文章数, status:{}, cause:{}", status, e);
}
return count;
}
@Override
public Integer countArticleComment() {
Integer count = 0;
try {
count = articleMapper.countArticleComment();
} catch (Exception e) {
e.printStackTrace();
log.error("统计文章评论数失败, cause:{}", e);
}
return count;
}
@Override
public Integer countArticleView() {
Integer count = 0;
try {
count = articleMapper.countArticleView();
} catch (Exception e) {
e.printStackTrace();
log.error("统计文章访问量失败, cause:{}", e);
}
return count;
}
@Override
public Integer countArticleByCategoryId(Integer categoryId) {
Integer count = 0;
try {
count = articleCategoryRefMapper.countArticleByCategoryId(categoryId);
} catch (Exception e) {
e.printStackTrace();
log.error("根据分类统计文章数量失败, categoryId:{}, cause:{}", categoryId, e);
}
return count;
}
@Override
public Integer countArticleByTagId(Integer tagId) {
return articleTagRefMapper.countArticleByTagId(tagId);
}
//sjhdfg
@Override
public List<Article> listArticle(HashMap<String, Object> criteria) {
return articleMapper.findAll(criteria);
}
@Override
public List<Article> listRecentArticle(Integer userId, Integer limit) {
return articleMapper.listArticleByLimit(userId, limit);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateArticleDetail(Article article) {
article.setArticleUpdateTime(new Date());
articleMapper.update(article);
if (article.getTagList() != null) {
//删除标签和文章关联
articleTagRefMapper.deleteByArticleId(article.getArticleId());
//添加标签和文章关联
for (int i = 0; i < article.getTagList().size(); i++) {
ArticleTagRef articleTagRef = new ArticleTagRef(article.getArticleId(), article.getTagList().get(i).getTagId());
articleTagRefMapper.insert(articleTagRef);
}
}
if (article.getCategoryList() != null) {
//添加分类和文章关联
articleCategoryRefMapper.deleteByArticleId(article.getArticleId());
//删除分类和文章关联
for (int i = 0; i < article.getCategoryList().size(); i++) {
ArticleCategoryRef articleCategoryRef = new ArticleCategoryRef(article.getArticleId(), article.getCategoryList().get(i).getCategoryId());
articleCategoryRefMapper.insert(articleCategoryRef);
}
}
}
@Override
public void updateArticle(Article article) {
articleMapper.update(article);
}
@Override
public void deleteArticleBatch(List<Integer> ids) {
articleMapper.deleteBatch(ids);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteArticle(Integer id) {
articleMapper.deleteById(id);
// 删除分类关联
articleCategoryRefMapper.deleteByArticleId(id);
// 删除标签管理
articleTagRefMapper.deleteByArticleId(id);
// 删除评论
commentMapper.deleteByArticleId(id);
}
@Override
public PageInfo<Article> pageArticle(Integer pageIndex,
Integer pageSize,
HashMap<String, Object> criteria) {
PageHelper.startPage(pageIndex, pageSize);
List<Article> articleList = articleMapper.findAll(criteria);
for (int i = 0; i < articleList.size(); i++) {
//封装CategoryList
List<Category> categoryList = articleCategoryRefMapper.listCategoryByArticleId(articleList.get(i).getArticleId());
if (categoryList == null || categoryList.size() == 0) {
categoryList = new ArrayList<>();
categoryList.add(Category.Default());
}
articleList.get(i).setCategoryList(categoryList);
articleList.get(i).setUser(userMapper.getUserById(articleList.get(i).getArticleUserId()));
// //封装TagList
// List<Tag> tagList = articleTagRefMapper.listTagByArticleId(articleList.get(i).getArticleId());
// articleList.get(i).setTagList(tagList);
}
return new PageInfo<>(articleList);
}
@Override
public Article getArticleByStatusAndId(Integer status, Integer id) {
Article article = articleMapper.getArticleByStatusAndId(status, id);
if (article != null) {
List<Category> categoryList = articleCategoryRefMapper.listCategoryByArticleId(article.getArticleId());
List<Tag> tagList = articleTagRefMapper.listTagByArticleId(article.getArticleId());
article.setCategoryList(categoryList);
article.setTagList(tagList);
}
return article;
}
@Override
public List<Article> listArticleByViewCount(Integer limit) {
return articleMapper.listArticleByViewCount(limit);
}
@Override
public Article getAfterArticle(Integer id) {
return articleMapper.getAfterArticle(id);
}
@Override
public Article getPreArticle(Integer id) {
return articleMapper.getPreArticle(id);
}
@Override
public List<Article> listRandomArticle(Integer limit) {
return articleMapper.listRandomArticle(limit);
}
@Override
public List<Article> listArticleByCommentCount(Integer limit) {
return articleMapper.listArticleByCommentCount(limit);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void insertArticle(Article article) {
//添加文章
article.setArticleCreateTime(new Date());
article.setArticleUpdateTime(new Date());
article.setArticleIsComment(ArticleCommentStatus.ALLOW.getValue());
article.setArticleViewCount(0);
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++) {
ArticleCategoryRef articleCategoryRef = new ArticleCategoryRef(article.getArticleId(), article.getCategoryList().get(i).getCategoryId());
articleCategoryRefMapper.insert(articleCategoryRef);
}
//添加标签和文章关联
for (int i = 0; i < article.getTagList().size(); i++) {
ArticleTagRef articleTagRef = new ArticleTagRef(article.getArticleId(), article.getTagList().get(i).getTagId());
articleTagRefMapper.insert(articleTagRef);
}
}
@Override
public void updateCommentCount(Integer articleId) {
articleMapper.updateCommentCount(articleId);
}
@Override
public Article getLastUpdateArticle() {
return articleMapper.getLastUpdateArticle();
}
@Override
public List<Article> listArticleByCategoryId(Integer cateId, Integer limit) {
return articleMapper.findArticleByCategoryId(cateId, limit);
}
@Override
public List<Article> listArticleByCategoryIds(List<Integer> cateIds, Integer limit) {
if (cateIds == null || cateIds.size() == 0) {
return null;
}
return articleMapper.findArticleByCategoryIds(cateIds, limit);
}
@Override
public List<Integer> listCategoryIdByArticleId(Integer articleId) {
return articleCategoryRefMapper.selectCategoryIdByArticleId(articleId);
}
@Override
public List<Article> listAllNotWithContent() {
return articleMapper.listAllNotWithContent();
}
}

@ -0,0 +1,76 @@
package com.liuyanzhao.ssm.blog.service;
import com.liuyanzhao.ssm.blog.entity.Category;
import java.util.List;
/**
* @author
* @date 2017/8/24
*/
public interface CategoryService {
/**
*
*
* @return
*/
Integer countCategory();
/**
*
*
* @return
*/
List<Category> listCategory();
/**
*
*
* @return
*/
List<Category> listCategoryWithCount();
/**
*
*
* @param id ID
*/
void deleteCategory(Integer id);
/**
* id
*
* @param id ID
* @return
*/
Category getCategoryById(Integer id);
/**
*
*
* @param category
* @return
*/
Category insertCategory(Category category);
/**
*
*
* @param category
*/
void updateCategory(Category category);
/**
*
*
* @param name
* @return
*/
Category getCategoryByName(String name);
}

@ -0,0 +1,105 @@
package com.liuyanzhao.ssm.blog.service;
import com.github.pagehelper.PageInfo;
import com.liuyanzhao.ssm.blog.entity.Comment;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
/**
* @author
* @date 2017/9/10
*/
@Service
public interface CommentService {
/**
*
*
* @param comment
*/
void insertComment(Comment comment);
/**
* id
*
* @param articleId ID
* @return
*/
List<Comment> listCommentByArticleId(Integer articleId);
/**
* id
*
* @param id
* @return
*/
Comment getCommentById(Integer id);
/**
*
*
* @param pageIndex
* @param pageSize
* @return
*/
PageInfo<Comment> listCommentByPage(
Integer pageIndex,
Integer pageSize,
HashMap<String, Object> criteria);
/**
*
*
* @param pageIndex
* @param pageSize
* @return
*/
PageInfo<Comment> listReceiveCommentByPage(
Integer pageIndex,
Integer pageSize,
Integer userId);
/**
*
*
* @param id ID
*/
void deleteComment(Integer id);
/**
*
*
* @param comment
*/
void updateComment(Comment comment);
/**
*
*
* @return
*/
Integer countComment();
/**
*
*
* @param limit
* @return
*/
List<Comment> listRecentComment(Integer userId, Integer limit);
/**
*
*
* @param id ID
* @return
*/
List<Comment> listChildComment(Integer id);
}

@ -0,0 +1,60 @@
package com.liuyanzhao.ssm.blog.service;
import com.liuyanzhao.ssm.blog.entity.Link;
import java.util.List;
/**
*
* @author
* @date 2017/9/4
*/
public interface LinkService {
/**
*
*
* @param status
* @return
*/
Integer countLink(Integer status);
/**
*
*
* @param status
* @return
*/
List<Link> listLink(Integer status);
/**
*
*
* @param link
*/
void insertLink(Link link);
/**
*
*
* @param id ID
*/
void deleteLink(Integer id);
/**
*
*
* @param link
*/
void updateLink(Link link);
/**
* id
*
* @param id ID
* @return
*/
Link getLinkById(Integer id);
}

@ -0,0 +1,46 @@
package com.liuyanzhao.ssm.blog.service;
import com.liuyanzhao.ssm.blog.entity.Menu;
import java.util.List;
/**
* @author liuyanzhao
*/
public interface MenuService {
/**
*
*
* @return
*/
List<Menu> listMenu() ;
/**
*
*
* @param menu
*/
Menu insertMenu(Menu menu) ;
/**
*
*
* @param id ID
*/
void deleteMenu(Integer id) ;
/**
*
*
* @param menu
*/
void updateMenu(Menu menu) ;
/**
* id
*
* @param id ID
* @return
*/
Menu getMenuById(Integer id) ;
}

@ -0,0 +1,50 @@
package com.liuyanzhao.ssm.blog.service;
import com.liuyanzhao.ssm.blog.entity.Notice;
import java.util.List;
/**
* @author liuyanzhao
*/
public interface NoticeService {
/**
*
*
* @param status
* @return
*/
List<Notice> listNotice(Integer status);
/**
*
*
* @param notice
*/
void insertNotice(Notice notice);
/**
*
*
* @param id
*/
void deleteNotice(Integer id);
/**
*
*
* @param notice
*/
void updateNotice(Notice notice);
/**
* id
*
* @param id ID
* @return
*/
Notice getNoticeById(Integer id);
}

@ -0,0 +1,32 @@
package com.liuyanzhao.ssm.blog.service;
import com.liuyanzhao.ssm.blog.entity.Options;
/**
*
* @author
* @date 2017/9/7
*/
public interface OptionsService {
/**
*
*
* @return
*/
Options getOptions();
/**
*
*
* @param options
*/
void insertOptions(Options options);
/**
*
*
* @param options
*/
void updateOptions(Options options);
}

@ -0,0 +1,58 @@
package com.liuyanzhao.ssm.blog.service;
import com.liuyanzhao.ssm.blog.entity.Page;
import java.util.List;
/**
*
* @author
* @date 2017/9/7
*/
public interface PageService {
/**
*
*
* @param status
* @return
*/
List<Page> listPage(Integer status);
/**
* key
*
* @param status
* @param key
* @return
*/
Page getPageByKey(Integer status, String key);
/**
* id
*
* @param id ID
* @return
*/
Page getPageById(Integer id);
/**
*
*
* @param page
*/
void insertPage(Page page);
/**
*
*
* @param id ID
*/
void deletePage(Integer id);
/**
*
*
* @param page
*/
void updatePage(Page page);
}

@ -0,0 +1,82 @@
package com.liuyanzhao.ssm.blog.service;
import com.liuyanzhao.ssm.blog.entity.Tag;
import java.util.List;
/**
*
* @author
* @date 2017/9/2
*/
public interface TagService {
/**
*
*
* @return
*/
Integer countTag() ;
/**
*
*
* @return
*/
List<Tag> listTag() ;
/**
*
*
* @return
*/
List<Tag> listTagWithCount() ;
/**
* id
*
* @param id ID
* @return
*/
Tag getTagById(Integer id) ;
/**
*
*
* @param tag
* @return
*/
Tag insertTag(Tag tag) ;
/**
*
*
* @param tag
*/
void updateTag(Tag tag) ;
/**
*
*
* @param id iD
*/
void deleteTag(Integer id) ;
/**
*
*
* @param name
* @return
*/
Tag getTagByName(String name) ;
/**
* ID
*
* @param articleId ID
* @return
*/
List<Tag> listTagByArticleId(Integer articleId);
}

@ -0,0 +1,73 @@
package com.liuyanzhao.ssm.blog.service;
import com.liuyanzhao.ssm.blog.entity.User;
import java.util.List;
/**
* @author
* @date 2017/8/24
*/
public interface UserService {
/**
*
*
* @return
*/
List<User> listUser();
/**
* id
*
* @param id ID
* @return
*/
User getUserById(Integer id);
/**
*
*
* @param user
*/
void updateUser(User user);
/**
*
*
* @param id ID
*/
void deleteUser(Integer id);
/**
*
*
* @param user
* @return
*/
User insertUser(User user);
/**
*
*
* @param str Email
* @return
*/
User getUserByNameOrEmail(String str);
/**
*
*
* @param name
* @return
*/
User getUserByName(String name);
/**
*
*
* @param email Email
* @return
*/
User getUserByEmail(String email);
}

@ -0,0 +1,286 @@
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 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;
import java.util.HashMap;
import java.util.List;
/**
* Servie
*
* @author
* @date 2017/8/24
*/
@Service
@Slf4j
public class ArticleServiceImpl implements ArticleService {
@Autowired
private ArticleMapper articleMapper;
@Autowired
private ArticleCategoryRefMapper articleCategoryRefMapper;
@Autowired
private ArticleTagRefMapper articleTagRefMapper;
@Autowired
private UserMapper userMapper;
@Autowired
private CommentMapper commentMapper;
@Override
public Integer countArticle(Integer status) {
Integer count = 0;
try {
count = articleMapper.countArticle(status);
} catch (Exception e) {
e.printStackTrace();
log.error("根据状态统计文章数, status:{}, cause:{}", status, e);
}
return count;
}
@Override
public Integer countArticleComment() {
Integer count = 0;
try {
count = articleMapper.countArticleComment();
} catch (Exception e) {
e.printStackTrace();
log.error("统计文章评论数失败, cause:{}", e);
}
return count;
}
@Override
public Integer countArticleView() {
Integer count = 0;
try {
count = articleMapper.countArticleView();
} catch (Exception e) {
e.printStackTrace();
log.error("统计文章访问量失败, cause:{}", e);
}
return count;
}
@Override
public Integer countArticleByCategoryId(Integer categoryId) {
Integer count = 0;
try {
count = articleCategoryRefMapper.countArticleByCategoryId(categoryId);
} catch (Exception e) {
e.printStackTrace();
log.error("根据分类统计文章数量失败, categoryId:{}, cause:{}", categoryId, e);
}
return count;
}
@Override
public Integer countArticleByTagId(Integer tagId) {
return articleTagRefMapper.countArticleByTagId(tagId);
}
@Override
public List<Article> listArticle(HashMap<String, Object> criteria) {
return articleMapper.findAll(criteria);
}
@Override
public List<Article> listRecentArticle(Integer userId, Integer limit) {
return articleMapper.listArticleByLimit(userId, limit);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateArticleDetail(Article article) {
article.setArticleUpdateTime(new Date());
articleMapper.update(article);
if (article.getTagList() != null) {
//删除标签和文章关联
articleTagRefMapper.deleteByArticleId(article.getArticleId());
//添加标签和文章关联
for (int i = 0; i < article.getTagList().size(); i++) {
ArticleTagRef articleTagRef = new ArticleTagRef(article.getArticleId(), article.getTagList().get(i).getTagId());
articleTagRefMapper.insert(articleTagRef);
}
}
if (article.getCategoryList() != null) {
//添加分类和文章关联
articleCategoryRefMapper.deleteByArticleId(article.getArticleId());
//删除分类和文章关联
for (int i = 0; i < article.getCategoryList().size(); i++) {
ArticleCategoryRef articleCategoryRef = new ArticleCategoryRef(article.getArticleId(), article.getCategoryList().get(i).getCategoryId());
articleCategoryRefMapper.insert(articleCategoryRef);
}
}
}
@Override
public void updateArticle(Article article) {
articleMapper.update(article);
}
@Override
public void deleteArticleBatch(List<Integer> ids) {
articleMapper.deleteBatch(ids);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteArticle(Integer id) {
articleMapper.deleteById(id);
// 删除分类关联
articleCategoryRefMapper.deleteByArticleId(id);
// 删除标签管理
articleTagRefMapper.deleteByArticleId(id);
// 删除评论
commentMapper.deleteByArticleId(id);
}
@Override
public PageInfo<Article> pageArticle(Integer pageIndex,
Integer pageSize,
HashMap<String, Object> criteria) {
PageHelper.startPage(pageIndex, pageSize);
List<Article> articleList = articleMapper.findAll(criteria);
for (int i = 0; i < articleList.size(); i++) {
//封装CategoryList
List<Category> categoryList = articleCategoryRefMapper.listCategoryByArticleId(articleList.get(i).getArticleId());
if (categoryList == null || categoryList.size() == 0) {
categoryList = new ArrayList<>();
categoryList.add(Category.Default());
}
articleList.get(i).setCategoryList(categoryList);
articleList.get(i).setUser(userMapper.getUserById(articleList.get(i).getArticleUserId()));
// //封装TagList
// List<Tag> tagList = articleTagRefMapper.listTagByArticleId(articleList.get(i).getArticleId());
// articleList.get(i).setTagList(tagList);
}
return new PageInfo<>(articleList);
}
@Override
public Article getArticleByStatusAndId(Integer status, Integer id) {
Article article = articleMapper.getArticleByStatusAndId(status, id);
if (article != null) {
List<Category> categoryList = articleCategoryRefMapper.listCategoryByArticleId(article.getArticleId());
List<Tag> tagList = articleTagRefMapper.listTagByArticleId(article.getArticleId());
article.setCategoryList(categoryList);
article.setTagList(tagList);
}
return article;
}
@Override
public List<Article> listArticleByViewCount(Integer limit) {
return articleMapper.listArticleByViewCount(limit);
}
@Override
public Article getAfterArticle(Integer id) {
return articleMapper.getAfterArticle(id);
}
@Override
public Article getPreArticle(Integer id) {
return articleMapper.getPreArticle(id);
}
@Override
public List<Article> listRandomArticle(Integer limit) {
return articleMapper.listRandomArticle(limit);
}
@Override
public List<Article> listArticleByCommentCount(Integer limit) {
return articleMapper.listArticleByCommentCount(limit);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void insertArticle(Article article) {
//添加文章
article.setArticleCreateTime(new Date());
article.setArticleUpdateTime(new Date());
article.setArticleIsComment(ArticleCommentStatus.ALLOW.getValue());
article.setArticleViewCount(0);
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++) {
ArticleCategoryRef articleCategoryRef = new ArticleCategoryRef(article.getArticleId(), article.getCategoryList().get(i).getCategoryId());
articleCategoryRefMapper.insert(articleCategoryRef);
}
//添加标签和文章关联
for (int i = 0; i < article.getTagList().size(); i++) {
ArticleTagRef articleTagRef = new ArticleTagRef(article.getArticleId(), article.getTagList().get(i).getTagId());
articleTagRefMapper.insert(articleTagRef);
}
}
@Override
public void updateCommentCount(Integer articleId) {
articleMapper.updateCommentCount(articleId);
}
@Override
public Article getLastUpdateArticle() {
return articleMapper.getLastUpdateArticle();
}
@Override
public List<Article> listArticleByCategoryId(Integer cateId, Integer limit) {
return articleMapper.findArticleByCategoryId(cateId, limit);
}
@Override
public List<Article> listArticleByCategoryIds(List<Integer> cateIds, Integer limit) {
if (cateIds == null || cateIds.size() == 0) {
return null;
}
return articleMapper.findArticleByCategoryIds(cateIds, limit);
}
@Override
public List<Integer> listCategoryIdByArticleId(Integer articleId) {
return articleCategoryRefMapper.selectCategoryIdByArticleId(articleId);
}
@Override
public List<Article> listAllNotWithContent() {
return articleMapper.listAllNotWithContent();
}
}

@ -0,0 +1,133 @@
package com.liuyanzhao.ssm.blog.service.impl;
import com.liuyanzhao.ssm.blog.mapper.ArticleCategoryRefMapper;
import com.liuyanzhao.ssm.blog.mapper.CategoryMapper;
import com.liuyanzhao.ssm.blog.entity.Category;
import com.liuyanzhao.ssm.blog.service.CategoryService;
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.transaction.interceptor.TransactionAspectSupport;
import java.util.List;
/**
*
*
* @author
* @date 2017/8/24
*/
@Service
@Slf4j
public class CategoryServiceImpl implements CategoryService {
@Autowired
private CategoryMapper categoryMapper;
@Autowired
private ArticleCategoryRefMapper articleCategoryRefMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteCategory(Integer id) {
try {
categoryMapper.deleteCategory(id);
articleCategoryRefMapper.deleteByCategoryId(id);
} catch (Exception e) {
e.printStackTrace();
log.error("删除分类失败, id:{}, cause:{}", id, e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
}
}
@Override
public Category getCategoryById(Integer id) {
Category category = null;
try {
category = categoryMapper.getCategoryById(id);
} catch (Exception e) {
e.printStackTrace();
log.error("根据分类ID获得分类, id:{}, cause:{}", id, e);
}
return category;
}
@Override
public void updateCategory(Category category) {
try {
categoryMapper.update(category);
} catch (Exception e) {
e.printStackTrace();
log.error("更新分类失败, category:{}, cause:{}", category, e);
}
}
@Override
public Category insertCategory(Category category) {
try {
categoryMapper.insert(category);
} catch (Exception e) {
e.printStackTrace();
log.error("创建分类失败, category:{}, cause:{}", category, e);
}
return category;
}
@Override
public Integer countCategory() {
Integer count = 0;
try {
count = categoryMapper.countCategory();
} catch (Exception e) {
e.printStackTrace();
log.error("统计分类失败, cause:{}", e);
}
return count;
}
@Override
public List<Category> listCategory() {
List<Category> categoryList = null;
try {
categoryList = categoryMapper.listCategory();
} catch (Exception e) {
e.printStackTrace();
log.error("根据文章获得分类列表失败, cause:{}", e);
}
return categoryList;
}
@Override
public List<Category> listCategoryWithCount() {
List<Category> categoryList = null;
try {
categoryList = categoryMapper.listCategory();
for (int i = 0; i < categoryList.size(); i++) {
Integer count = articleCategoryRefMapper.countArticleByCategoryId(categoryList.get(i).getCategoryId());
categoryList.get(i).setArticleCount(count);
}
} catch (Exception e) {
e.printStackTrace();
log.error("根据文章获得分类列表失败, cause:{}", e);
}
return categoryList;
}
@Override
public Category getCategoryByName(String name) {
Category category = null;
try {
category = categoryMapper.getCategoryByName(name);
} catch (Exception e) {
e.printStackTrace();
log.error("更新分类失败, category:{}, cause:{}", category, e);
}
return category;
}
}

@ -0,0 +1,165 @@
package com.liuyanzhao.ssm.blog.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liuyanzhao.ssm.blog.entity.Article;
import com.liuyanzhao.ssm.blog.entity.Comment;
import com.liuyanzhao.ssm.blog.enums.ArticleStatus;
import com.liuyanzhao.ssm.blog.mapper.CommentMapper;
import com.liuyanzhao.ssm.blog.mapper.ArticleMapper;
import com.liuyanzhao.ssm.blog.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* @author
* @date 2017/9/10
*/
@Service
@Slf4j
public class CommentServiceImpl implements CommentService {
@Autowired
private CommentMapper commentMapper;
@Autowired
private ArticleMapper articleMapper;
@Override
public void insertComment(Comment comment) {
try {
commentMapper.insert(comment);
} catch (Exception e) {
e.printStackTrace();
log.error("创建评论失败comment:{}, cause:{}", comment, e);
}
}
@Override
public List<Comment> listCommentByArticleId(Integer articleId) {
List<Comment> commentList = null;
try {
commentList = commentMapper.listCommentByArticleId(articleId);
} catch (Exception e) {
e.printStackTrace();
log.error("根据文章ID获得评论列表失败articleId:{},cause:{}", articleId, e);
}
return commentList;
}
@Override
public Comment getCommentById(Integer id) {
Comment comment = null;
try {
comment = commentMapper.getCommentById(id);
} catch (Exception e) {
e.printStackTrace();
log.error("根据评论ID获得评论id:{}, cause:{}", id, e);
}
return comment;
}
@Override
public PageInfo<Comment> listCommentByPage(Integer pageIndex, Integer pageSize, HashMap<String, Object> criteria) {
PageHelper.startPage(pageIndex, pageSize);
List<Comment> commentList = null;
try {
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);
}
} catch (Exception e) {
e.printStackTrace();
log.error("分页获得评论失败,pageIndex:{}, pageSize:{}, cause:{}", pageIndex, pageSize, e);
}
return new PageInfo<>(commentList);
}
@Override
public PageInfo<Comment> listReceiveCommentByPage(Integer pageIndex, Integer pageSize, Integer userId) {
PageHelper.startPage(pageIndex, pageSize);
List<Comment> commentList = new ArrayList<>();
try {
List<Integer> 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("分页获得评论失败,pageIndex:{}, pageSize:{}, cause:{}", pageIndex, pageSize, e);
}
return new PageInfo<>(commentList);
}
@Override
public void deleteComment(Integer id) {
try {
commentMapper.deleteById(id);
} catch (Exception e) {
e.printStackTrace();
log.error("删除评论失败, id:{}, cause:{}", id, e);
}
}
@Override
public void updateComment(Comment comment) {
try {
commentMapper.update(comment);
} catch (Exception e) {
e.printStackTrace();
log.error("更新评论comment:{}, cause:{}", comment, e);
}
}
@Override
public Integer countComment() {
Integer commentCount = null;
try {
commentCount = commentMapper.countComment();
} catch (Exception e) {
e.printStackTrace();
log.error("统计评论数量失败, cause:{}", e);
}
return commentCount;
}
@Override
public List<Comment> listRecentComment(Integer userId, Integer limit) {
List<Comment> commentList = null;
try {
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);
}
} catch (Exception e) {
e.printStackTrace();
log.error("获得最新评论失败, limit:{}, cause:{}", limit, e);
}
return commentList;
}
@Override
public List<Comment> listChildComment(Integer id) {
List<Comment> childCommentList = null;
try {
childCommentList = commentMapper.listChildComment(id);
} catch (Exception e) {
e.printStackTrace();
log.error("获得子评论失败, id:{}, cause:{}", id, e);
}
return childCommentList;
}
}

@ -0,0 +1,53 @@
package com.liuyanzhao.ssm.blog.service.impl;
import com.liuyanzhao.ssm.blog.entity.Link;
import com.liuyanzhao.ssm.blog.mapper.LinkMapper;
import com.liuyanzhao.ssm.blog.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
* @author
* @date 2017/9/4
*/
@Service
public class LinkServiceImpl implements LinkService {
@Autowired
private LinkMapper linkMapper;
@Override
public Integer countLink(Integer status) {
return linkMapper.countLink(status);
}
@Override
public List<Link> listLink(Integer status) {
return linkMapper.listLink(status);
}
@Override
public void insertLink(Link link) {
linkMapper.insert(link);
}
@Override
public void deleteLink(Integer id) {
linkMapper.deleteById(id);
}
@Override
public void updateLink(Link link) {
linkMapper.update(link);
}
@Override
public Link getLinkById(Integer id) {
return linkMapper.getLinkById(id);
}
}

@ -0,0 +1,48 @@
package com.liuyanzhao.ssm.blog.service.impl;
import com.liuyanzhao.ssm.blog.entity.Menu;
import com.liuyanzhao.ssm.blog.mapper.MenuMapper;
import com.liuyanzhao.ssm.blog.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author liuyanzhao
*/
@Service
public class MenuServiceImpl implements MenuService {
@Autowired
private MenuMapper menuMapper;
@Override
public List<Menu> listMenu() {
List<Menu> menuList = menuMapper.listMenu();
return menuList;
}
@Override
public Menu insertMenu(Menu menu) {
menuMapper.insert(menu);
return menu;
}
@Override
public void deleteMenu(Integer id) {
menuMapper.deleteById(id);
}
@Override
public void updateMenu(Menu menu) {
menuMapper.update(menu);
}
@Override
public Menu getMenuById(Integer id) {
return menuMapper.getMenuById(id);
}
}

@ -0,0 +1,46 @@
package com.liuyanzhao.ssm.blog.service.impl;
import com.liuyanzhao.ssm.blog.entity.Notice;
import com.liuyanzhao.ssm.blog.mapper.NoticeMapper;
import com.liuyanzhao.ssm.blog.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author liuyanzhao
*/
@Service
public class NoticeServiceImpl implements NoticeService {
@Autowired
private NoticeMapper noticeMapper;
@Override
public List<Notice> listNotice(Integer status) {
return noticeMapper.listNotice(status);
}
@Override
public void insertNotice(Notice notice) {
noticeMapper.insert(notice);
}
@Override
public void deleteNotice(Integer id) {
noticeMapper.deleteById(id);
}
@Override
public void updateNotice(Notice notice) {
noticeMapper.update(notice);
}
@Override
public Notice getNoticeById(Integer id) {
return noticeMapper.getNoticeById(id);
}
}

@ -0,0 +1,40 @@
package com.liuyanzhao.ssm.blog.service.impl;
import com.liuyanzhao.ssm.blog.entity.Options;
import com.liuyanzhao.ssm.blog.mapper.OptionsMapper;
import com.liuyanzhao.ssm.blog.service.OptionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
/**
*
* @author
* @date 2017/9/7
*/
@Service
public class OptionsServiceImpl implements OptionsService {
@Autowired
private OptionsMapper optionsMapper;
@Override
@Cacheable(value = "default", key = "'options'")
public Options getOptions() {
return optionsMapper.getOptions();
}
@Override
@CacheEvict(value = "default", key = "'options'")
public void insertOptions(Options options) {
optionsMapper.insert(options);
}
@Override
@CacheEvict(value = "default", key = "'options'")
public void updateOptions(Options options) {
optionsMapper.update(options);
}
}

@ -0,0 +1,52 @@
package com.liuyanzhao.ssm.blog.service.impl;
import com.liuyanzhao.ssm.blog.entity.Page;
import com.liuyanzhao.ssm.blog.mapper.PageMapper;
import com.liuyanzhao.ssm.blog.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author
* @date 2017/9/7
*/
@Service
public class PageServiceImpl implements PageService {
@Autowired
private PageMapper pageMapper;
@Override
public Page getPageByKey(Integer status, String key) {
return pageMapper.getPageByKey(status, key);
}
@Override
public Page getPageById(Integer id) {
return pageMapper.getPageById(id);
}
@Override
public List<Page> listPage(Integer status) {
return pageMapper.listPage(status);
}
@Override
public void insertPage(Page page) {
pageMapper.insert(page);
}
@Override
public void deletePage(Integer id) {
pageMapper.deleteById(id);
}
@Override
public void updatePage(Page page) {
pageMapper.update(page);
}
}

@ -0,0 +1,133 @@
package com.liuyanzhao.ssm.blog.service.impl;
import com.liuyanzhao.ssm.blog.mapper.ArticleTagRefMapper;
import com.liuyanzhao.ssm.blog.mapper.TagMapper;
import com.liuyanzhao.ssm.blog.entity.Tag;
import com.liuyanzhao.ssm.blog.service.TagService;
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.transaction.interceptor.TransactionAspectSupport;
import java.util.List;
/**
* @author
* @date 2017/9/2
*/
@Service
@Slf4j
public class TagServiceImpl implements TagService {
@Autowired
private TagMapper tagMapper;
@Autowired
private ArticleTagRefMapper articleTagRefMapper;
@Override
public Integer countTag() {
return tagMapper.countTag();
}
@Override
public List<Tag> listTag() {
List<Tag> tagList = null;
try {
tagList = tagMapper.listTag();
} catch (Exception e) {
e.printStackTrace();
log.error("获得所有标签失败, cause:{}", e);
}
return tagList;
}
@Override
public List<Tag> listTagWithCount() {
List<Tag> tagList = null;
try {
tagList = tagMapper.listTag();
for (int i = 0; i < tagList.size(); i++) {
Integer count = articleTagRefMapper.countArticleByTagId(tagList.get(i).getTagId());
tagList.get(i).setArticleCount(count);
}
} catch (Exception e) {
e.printStackTrace();
log.error("获得所有标签失败, cause:{}", e);
}
return tagList;
}
@Override
public Tag getTagById(Integer id) {
Tag tag = null;
try {
tag = tagMapper.getTagById(id);
} catch (Exception e) { e.printStackTrace();
log.error("根据ID获得标签失败, id:{}, cause:{}", id, e);
}
return tag;
}
@Override
public Tag insertTag(Tag tag) {
try {
tagMapper.insert(tag);
} catch (Exception e) {
e.printStackTrace();
log.error("添加标签失败, tag:{}, cause:{}", tag, e);
}
return tag;
}
@Override
public void updateTag(Tag tag) {
try {
tagMapper.update(tag);
} catch (Exception e) {
e.printStackTrace();
log.error("更新标签失败, tag:{}, cause:{}", tag, e);
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteTag(Integer id) {
try {
tagMapper.deleteById(id);
articleTagRefMapper.deleteByTagId(id);
} catch (Exception e) {
e.printStackTrace();
log.error("删除标签失败, id:{}, cause:{}", id, e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
}
}
@Override
public Tag getTagByName(String name) {
Tag tag = null;
try {
tag = tagMapper.getTagByName(name);
} catch (Exception e) { e.printStackTrace();
log.error("根据名称获得标签, name:{}, cause:{}", name, e);
}
return tag;
}
@Override
public List<Tag> listTagByArticleId(Integer articleId) {
List<Tag> tagList = null;
try {
tagList = articleTagRefMapper.listTagByArticleId(articleId);
} catch (Exception e) {
e.printStackTrace();
log.error("根据文章ID获得标签失败articleId:{}, cause:{}", articleId, e);
}
return tagList;
}
}

@ -0,0 +1,95 @@
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;
/**
*
*
* @author
* @date 2017/8/24
*/
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Autowired
private ArticleMapper articleMapper;
@Autowired
private ArticleService articleService;
@Autowired
private CommentMapper commentMapper;
@Override
public List<User> listUser() {
List<User> userList = userMapper.listUser();
for (int i = 0; i < userList.size(); i++) {
Integer articleCount = articleMapper.countArticleByUser(userList.get(i).getUserId());
userList.get(i).setArticleCount(articleCount);
}
return userList;
}
@Override
public User getUserById(Integer id) {
return userMapper.getUserById(id);
}
@Override
public void updateUser(User user) {
userMapper.update(user);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteUser(Integer id) {
// 删除用户
userMapper.deleteById(id);
// 删除评论
commentMapper.deleteByUserId(id);
// 删除文章
List<Integer> articleIds = articleMapper.listArticleIdsByUserId(id);
if (articleIds != null && articleIds.size() > 0) {
for (Integer articleId : articleIds) {
articleService.deleteArticle(articleId);
}
}
}
@Override
public User insertUser(User user) {
user.setUserRegisterTime(new Date());
userMapper.insert(user);
return user;
}
@Override
public User getUserByNameOrEmail(String str) {
return userMapper.getUserByNameOrEmail(str);
}
@Override
public User getUserByName(String name) {
return userMapper.getUserByName(name);
}
@Override
public User getUserByEmail(String email) {
return userMapper.getUserByEmail(email);
}
}

@ -0,0 +1,92 @@
package com.liuyanzhao.ssm.blog.util;
import javax.servlet.http.HttpServletRequest;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*
* Created by on 2017/8/24.
*/
public class MyUtils {
/**
* IP
*
* @param request
* @return
*/
public static String getIpAddr(HttpServletRequest request) {
String ipAddress = request.getHeader("x-forwarded-for");
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("Proxy-Client-IP");
}
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("WL-Proxy-Client-IP");
}
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getRemoteAddr();
}
//对于通过多个代理的情况第一个IP为客户端真实IP,多个IP按照','分割
if (ipAddress != null && ipAddress.length() > 15) {
if (ipAddress.indexOf(",") > 0) {
ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
}
}
return ipAddress;
}
/**
* Md5
*
* @param str
* @return
*/
public static String strToMd5(String str) {
String md5Str = null;
if (str != null && str.length() != 0) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(str.getBytes());
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0) {
i += 256;
}
if (i < 16) {
buf.append("0");
}
buf.append(Integer.toHexString(i));
}
//32位
md5Str = buf.toString();
//16位
//md5Str = buf.toString().substring(8, 24);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
return md5Str;
}
/**
* emailgravatar
*
* @param email Email
* @return URL
*/
public static String getGravatar(String email) {
String emailMd5 = strToMd5(email);
//设置图片大小32px
String avatar = "http://cn.gravatar.com/avatar/" + emailMd5 + "?s=128&d=identicon&r=PG";
return avatar;
}
}

@ -0,0 +1,5 @@
#MySQL
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

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 尽量别用绝对路径,如果带参数不同容器路径解释可能不同,以下配置参数在pom.xml里 -->
<property name="log.root.level" value="INFO"/> <!-- 日志级别 -->
<property name="log.other.level" value="ERROR"/> <!-- 其他日志级别 -->
<property name="log.base" value="logs"/> <!-- 日志路径这里是相对路径默认会输出到tomcat/bin目录 下 -->
<property name="log.moduleName" value="ForestBlog"/> <!-- 模块名称, 影响日志配置名,日志文件名 -->
<property name="log.max.size" value="20MB"/> <!-- 日志文件大小 -->
<!--控制台输出 -->
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread]%logger{56}.%method:%L -%msg%n</Pattern>
</encoder>
</appender>
<!-- 日志文件输出 -->
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${log.base}/${log.moduleName}.log
</File><!-- 设置日志不超过${log.max.size}时的保存路径,注意如果 是web项目会保存到Tomcat的bin目录 下 -->
<!-- 滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件。-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${log.base}/archive/${log.moduleName}_all_%d{yyyy-MM-dd}.%i.log.zip
</FileNamePattern>
<!-- 当天的日志大小 超过${log.max.size}时,压缩日志并保存 -->
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>${log.max.size}</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<!-- 日志输出的文件的格式 -->
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread]%logger{56}.%method:%L -%msg%n</pattern>
</layout>
</appender>
</configuration>

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 定义了一个名为com.liuyanzhao.ssm.blog.mapper.ArticleCategoryRefMapper的命名空间用于组织SQL语句 -->
<mapper namespace="com.liuyanzhao.ssm.blog.mapper.ArticleCategoryRefMapper">
<!-- 定义了一个resultMap用于映射数据库列和Java对象属性 -->
<resultMap id="BaseResultMap" type="com.liuyanzhao.ssm.blog.entity.ArticleCategoryRef">
<!-- 将数据库列article_id映射到Java对象的articleId属性 -->
<result column="article_id" jdbcType="INTEGER" property="articleId"/>
<!-- 将数据库列category_id映射到Java对象的categoryId属性 -->
<result column="category_id" jdbcType="INTEGER" property="categoryId"/>
</resultMap>
<!-- 定义了一个SQL片段用于在其他SQL语句中引用表名 -->
<sql id="tb">article_category_ref</sql>
<!-- 定义了一个插入操作,用于将文章和分类的关联关系插入到数据库 -->
<insert id="insert" parameterType="java.lang.Integer">
insert into
<include refid="tb"/>
(article_id, category_id)
values (#{articleId}, #{categoryId})
</insert>
<!-- 定义了一个删除操作用于根据分类ID删除文章和分类的关联关系 -->
<delete id="deleteByCategoryId" parameterType="java.lang.Integer">
delete from
<include refid="tb"/>
where category_id = #{value}
</delete>
<!-- 定义了一个删除操作用于根据文章ID删除文章和分类的关联关系 -->
<delete id="deleteByArticleId" parameterType="java.lang.Integer">
delete from
<include refid="tb"/>
where article_id = #{value}
</delete>
<!-- 定义了一个查询操作,用于统计某个分类下的文章数量 -->
<select id="countArticleByCategoryId" parameterType="java.lang.Integer" resultType="java.lang.Integer">
select count(*) from
<include refid="tb"/>
where category_id = #{value}
</select>
<!-- 定义了一个查询操作用于根据文章ID查询该文章关联的分类ID -->
<select id="selectCategoryIdByArticleId" resultType="java.lang.Integer">
SELECT category_id FROM
<include refid="tb"/>
WHERE article_id = #{value}
</select>
<!-- 定义了一个查询操作用于根据分类ID查询该分类下的所有文章ID -->
<select id="selectArticleIdByCategoryId" resultType="java.lang.Integer">
SELECT article_id FROM
<include refid="tb"/>
WHERE category_id = #{value}
</select>
<!-- 定义了一个查询操作用于根据文章ID查询该文章关联的所有分类 -->
<select id="listCategoryByArticleId" parameterType="java.lang.Integer"
resultType="com.liuyanzhao.ssm.blog.entity.Category">
SELECT
category.category_id, category.category_pid, category.category_name
FROM category, article_category_ref
WHERE article_category_ref.article_id = #{value} AND
article_category_ref.category_id = category.category_id
ORDER BY category.category_pid asc
</select>
</mapper>

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 定义了一个名为com.liuyanzhao.ssm.blog.mapper.ArticleMapper的命名空间用于组织SQL语句 -->
<mapper namespace="com.liuyanzhao.ssm.blog.mapper.ArticleMapper">
<!-- 定义了一个resultMap用于映射数据库列和Java对象属性 -->
<resultMap id="BaseResultMap" type="com.liuyanzhao.ssm.blog.entity.Article">
<id column="article_id" property="articleId" jdbcType="INTEGER"/> <!-- 主键字段 -->
<result column="article_user_id" property="articleUserId" jdbcType="INTEGER"/> <!-- 文章作者ID -->
<result column="article_title" property="articleTitle" jdbcType="VARCHAR"/> <!-- 文章标题 -->
<result column="article_content" property="articleContent" jdbcType="LONGVARCHAR"/> <!-- 文章内容 -->
<result column="article_summary" property="articleSummary" jdbcType="VARCHAR"/> <!-- 文章摘要 -->
<result column="article_view_count" property="articleViewCount" jdbcType="INTEGER"/> <!-- 浏览次数 -->
<result column="article_comment_count" property="articleCommentCount" jdbcType="INTEGER"/> <!-- 评论次数 -->
<result column="article_like_count" property="articleLikeCount" jdbcType="INTEGER"/> <!-- 点赞次数 -->
<result column="article_is_comment" property="articleIsComment" jdbcType="INTEGER"/> <!-- 是否允许评论 -->
<result column="article_order" property="articleOrder" jdbcType="INTEGER"/> <!-- 排序字段 -->
<result column="article_create_time" property="articleCreateTime" jdbcType="TIMESTAMP"/> <!-- 创建时间 -->
<result column="article_update_time" property="articleUpdateTime" jdbcType="TIMESTAMP"/> <!-- 更新时间 -->
<result column="article_status" property="articleStatus" jdbcType="INTEGER"/> <!-- 文章状态 -->
<result column="article_thumbnail" property="articleThumbnail" jdbcType="VARCHAR"/> <!-- 文章缩略图 -->
</resultMap>
<!-- 定义了一个SQL片段用于在其他SQL语句中引用表名 -->
<sql id="tb">article</sql>
<!-- 定义了一个SQL片段用于在其他SQL语句中引用列名 -->
<sql id="Base_Column_List">
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_thumbnail
</sql>
<!-- 查询所有状态为1的文章不包含内容字段用于列表显示 -->
<select id="listAllNotWithContent" resultType="com.liuyanzhao.ssm.blog.entity.Article">
SELECT
article_id, article_user_id, article_title, article_create_time, article_thumbnail
FROM
<include refid="tb"/>
WHERE article_status = 1
ORDER BY article_id DESC
</select>
<!-- 查询所有文章支持多种条件的动态SQL -->
<select id="findAll" resultMap="BaseResultMap">
SELECT
article.* <!-- 使用resultMap中的列名 -->
FROM
article
<where>
<!-- 动态SQL根据条件构建查询 -->
<if test="status != null">
article.article_status = #{status} AND
</if>
<if test="keywords != null">
article.article_title LIKE concat(concat('%',#{keywords}),'%') AND
</if>
<if test="userId != null">
article.article_user_id = #{userId} AND
</if>
<if test="categoryId != null">
article.article_id IN (
SELECT article_category_ref.article_id FROM article_category_ref
WHERE article_category_ref.category_id = #{categoryId}
) AND
</if>
<if test="tagId != null">
article.article_id IN (
SELECT article_tag_ref.article_id FROM article_tag_ref
WHERE article_tag_ref.tag_id = #{tagId}
) AND
</if>
1 = 1 <!-- 总是为真的条件用于闭合AND -->
</where>
ORDER BY `article`.`article_order` DESC, `article`.`article_id` DESC
</select>
</mapper>

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 定义了一个名为com.liuyanzhao.ssm.blog.mapper.ArticleTagRefMapper的命名空间用于组织SQL语句 -->
<mapper namespace="com.liuyanzhao.ssm.blog.mapper.ArticleTagRefMapper">
<!-- 定义了一个resultMap用于映射数据库列和Java对象属性 -->
<resultMap id="BaseResultMap" type="com.liuyanzhao.ssm.blog.entity.ArticleTagRef">
<!-- 将数据库列article_id映射到Java对象的articleId属性 -->
<result column="article_id" jdbcType="INTEGER" property="articleId" />
<!-- 将数据库列tag_id映射到Java对象的tagId属性 -->
<result column="tag_id" jdbcType="INTEGER" property="tagId" />
</resultMap>
<!-- 定义了一个SQL片段用于在其他SQL语句中引用表名 -->
<sql id="tb">article_tag_ref</sql>
<!-- 定义了一个插入操作,用于将文章和标签的关联关系插入到数据库 -->
<insert id="insert" parameterType="java.lang.Integer" >
insert into <include refid="tb"/>
(article_id, tag_id)
values (#{articleId}, #{tagId})
</insert>
<!-- 定义了一个删除操作用于根据标签ID删除文章和标签的关联关系 -->
<delete id="deleteByTagId" parameterType="java.lang.Integer" >
delete from <include refid="tb"/> where tag_id = #{value}
</delete>
<!-- 定义了一个删除操作用于根据文章ID删除文章和标签的关联关系 -->
<delete id="deleteByArticleId" parameterType="java.lang.Integer" >
delete from <include refid="tb"/> where article_id = #{value}
</delete>
<!-- 定义了一个查询操作,用于统计某个标签下的文章数量 -->
<select id="countArticleByTagId" parameterType="java.lang.Integer" resultType="java.lang.Integer">
select count(*) from <include refid="tb"/>
where tag_id = #{value}
</select>
<!-- 定义了一个查询操作用于根据文章ID查询该文章关联的所有标签 -->
<select id="listTagByArticleId" parameterType="java.lang.Integer" resultType="com.liuyanzhao.ssm.blog.entity.Tag">
SELECT tag.* FROM tag, article_tag_ref
WHERE article_tag_ref.article_id = #{value} AND
article_tag_ref.tag_id = tag.tag_id
</select>
</mapper>

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 定义了一个名为com.liuyanzhao.ssm.blog.mapper.CategoryMapper的命名空间用于组织SQL语句 -->
<mapper namespace="com.liuyanzhao.ssm.blog.mapper.CategoryMapper">
<!-- 定义了一个resultMap用于映射数据库列和Java对象属性 -->
<resultMap id="BaseResultMap" type="com.liuyanzhao.ssm.blog.entity.Category">
<id column="category_id" property="categoryId" jdbcType="INTEGER"/> <!-- 分类ID -->
<result column="category_pid" property="categoryPid" jdbcType="INTEGER"/> <!-- 父分类ID -->
<result column="category_name" property="categoryName" jdbcType="VARCHAR"/> <!-- 分类名称 -->
<result column="category_description" property="categoryDescription" jdbcType="VARCHAR"/> <!-- 分类描述 -->
<result column="category_order" property="categoryOrder" jdbcType="INTEGER"/> <!-- 分类的排序 -->
<result column="category_icon" property="categoryIcon" jdbcType="VARCHAR"/> <!-- 分类的图标 -->
</resultMap>
<!-- 定义了一个SQL片段用于在其他SQL语句中引用表名 -->
<sql id="tb">category</sql>
<!-- 定义了一个SQL片段用于在其他SQL语句中引用列名 -->
<sql id="Base_Column_List">
category_id, category_pid, category_name, category_description, category_order, category_icon
</sql>
<!-- 插入一个新的分类 -->
<insert id="insert" parameterType="com.liuyanzhao.ssm.blog.entity.Category" useGeneratedKeys="true" keyProperty="categoryId">
insert into
<include refid="tb"/>
(category_pid, category_name, category_description, category_order, category_icon)
values (#{categoryPid,jdbcType=INTEGER}, #{categoryName,jdbcType=VARCHAR},
#{categoryDescription,jdbcType=VARCHAR}, #{categoryOrder,jdbcType=INTEGER}, #{categoryIcon,jdbcType=VARCHAR})
</insert>
<!-- 更新分类信息 -->
<update id="update" parameterType="com.liuyanzhao.ssm.blog.entity.Category">
update
<include refid="tb"/>
<set>
<if test="categoryPid != null">category_pid = #{categoryPid,jdbcType=INTEGER},</if>
<if test="categoryName != null">category_name = #{categoryName,jdbcType=VARCHAR},</if>
<if test="categoryDescription != null">category_description = #{categoryDescription,jdbcType=VARCHAR},</if>
<if test="categoryOrder != null">category_order = #{categoryOrder,jdbcType=INTEGER},</if>
<if test="categoryIcon != null">category_icon = #{categoryIcon,jdbcType=VARCHAR},</if>
</set>
where category_id = #{categoryId,jdbcType=INTEGER}
</update>
<!-- 获取分类总数 -->
<select id="countCategory" resultType="Integer">
SELECT COUNT(*) FROM
<include refid="tb"/>
</select>
<!-- 获取所有分类列表 -->
<select id="listCategory" resultType="com.liuyanzhao.ssm.blog.entity.Category">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="tb"/>
ORDER BY category_order DESC, category_id ASC
</select>
<!-- 根据ID获取分类 -->
<select id="getCategoryById" parameterType="Integer" resultType="com.liuyanzhao.ssm.blog.entity.Category">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="tb"/>
WHERE category_id = #{value}
</select>
<!-- 删除分类 -->
<delete id="deleteCategory" parameterType="Integer">
DELETE FROM
<include refid="tb"/>
WHERE category_id = #{value}
</delete>
<!-- 根据父分类ID查找子分类 -->
<select id="findChildCategory" parameterType="Integer" resultType="com.liuyanzhao.ssm.blog.entity.Category">
SELECT
<include refid="Base_Column_List"/>
FROM
`category`
WHERE category_pid = #{id}
</select>
<!-- 根据分类名称查找分类 -->
<select id="getCategoryByName" parameterType="String" resultType="com.liuyanzhao.ssm.blog.entity.Category">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="tb"/>
WHERE category_name = #{value}
LIMIT 1
</select>
</mapper>

@ -0,0 +1,172 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 定义了一个名为com.liuyanzhao.ssm.blog.mapper.CommentMapper的命名空间用于组织SQL语句 -->
<mapper namespace="com.liuyanzhao.ssm.blog.mapper.CommentMapper">
<!-- 定义了一个resultMap用于映射数据库列和Java对象属性 -->
<resultMap id="BaseResultMap" type="com.liuyanzhao.ssm.blog.entity.Comment">
<id column="comment_id" property="commentId" jdbcType="INTEGER"/> <!-- 评论ID -->
<result column="comment_pid" property="commentPid" jdbcType="INTEGER"/> <!-- 评论父ID -->
<result column="comment_pname" property="commentPname" jdbcType="VARCHAR"/> <!-- 评论父名称 -->
<result column="comment_article_id" property="commentArticleId" jdbcType="INTEGER"/> <!-- 文章ID -->
<result column="comment_author_name" property="commentAuthorName" jdbcType="VARCHAR"/> <!-- 评论作者名称 -->
<result column="comment_author_email" property="commentAuthorEmail" jdbcType="VARCHAR"/> <!-- 评论作者邮箱 -->
<result column="comment_author_url" property="commentAuthorUrl" jdbcType="VARCHAR"/> <!-- 评论作者网址 -->
<result column="comment_author_avatar" property="commentAuthorAvatar" jdbcType="VARCHAR"/> <!-- 评论作者头像 -->
<result column="comment_content" property="commentContent" jdbcType="VARCHAR"/> <!-- 评论内容 -->
<result column="comment_agent" property="commentAgent" jdbcType="VARCHAR"/> <!-- 评论代理 -->
<result column="comment_ip" property="commentIp" jdbcType="VARCHAR"/> <!-- 评论IP -->
<result column="comment_create_time" property="commentCreateTime" jdbcType="TIMESTAMP"/> <!-- 评论创建时间 -->
<result column="comment_role" property="commentRole" jdbcType="INTEGER"/> <!-- 评论角色 -->
<result column="comment_user_id" property="commentUserId" jdbcType="INTEGER"/> <!-- 评论用户ID -->
</resultMap>
<!-- 定义了一个SQL片段用于在其他SQL语句中引用表名 -->
<sql id="tb">comment</sql>
<!-- 定义了一个SQL片段用于在其他SQL语句中引用列名 -->
<sql id="Base_Column_List">
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_user_id
</sql>
<!-- 根据ID获取评论 -->
<select id="getCommentById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"/>
from
<include refid="tb"/>
where comment_id = #{commentId,jdbcType=INTEGER}
</select>
<!-- 根据ID删除评论 -->
<delete id="deleteById" parameterType="java.lang.Integer">
delete from
<include refid="tb"/>
where comment_id = #{commentId,jdbcType=INTEGER}
</delete>
<!-- 根据用户ID删除评论 -->
<delete id="deleteByUserId">
delete from
<include refid="tb"/>
WHERE comment_user_id = #{userId}
</delete>
<!-- 根据文章ID删除评论 -->
<delete id="deleteByArticleId">
delete from
<include refid="tb"/>
WHERE comment_article_id = #{articleId}
</delete>
<!-- 插入一个新的评论 -->
<insert id="insert" parameterType="com.liuyanzhao.ssm.blog.entity.Comment" useGeneratedKeys="true"
keyProperty="commentId">
insert into
<include refid="tb"/>
(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_user_id)
values (#{commentPid,jdbcType=INTEGER}, #{commentPname,jdbcType=VARCHAR}, #{commentArticleId,jdbcType=INTEGER},
#{commentAuthorName,jdbcType=VARCHAR}, #{commentAuthorEmail,jdbcType=VARCHAR},
#{commentAuthorUrl,jdbcType=VARCHAR},#{commentAuthorAvatar}, #{commentContent,jdbcType=VARCHAR},
#{commentAgent,jdbcType=VARCHAR},
#{commentIp,jdbcType=VARCHAR}, #{commentCreateTime,jdbcType=TIMESTAMP}, #{commentRole,jdbcType=INTEGER},
#{commentUserId,jdbcType=INTEGER})
</insert>
<!-- 更新评论信息 -->
<update id="update" parameterType="com.liuyanzhao.ssm.blog.entity.Comment">
update
<include refid="tb"/>
<set>
<if test="commentPid != null">comment_pid = #{commentPid,jdbcType=INTEGER},</if>
<if test="commentPname != null">comment_pname = #{commentPname,jdbcType=VARCHAR},</if>
<if test="commentArticleId != null">comment_article_id = #{commentArticleId,jdbcType=INTEGER},</if>
<if test="commentAuthorName != null">comment_author_name = #{commentAuthorName,jdbcType=VARCHAR},</if>
<if test="commentAuthorEmail != null">comment_author_email = #{commentAuthorEmail,jdbcType=VARCHAR},</if>
<if test="commentAuthorUrl != null">comment_author_url = #{commentAuthorUrl,jdbcType=VARCHAR},</if>
<if test="commentContent != null">comment_content = #{commentContent,jdbcType=VARCHAR},</if>
<if test="commentAgent != null">comment_agent = #{commentAgent,jdbcType=VARCHAR},</if>
<if test="commentIp != null">comment_ip = #{commentIp,jdbcType=VARCHAR},</if>
<if test="commentCreateTime != null">comment_create_time = #{commentCreateTime,jdbcType=TIMESTAMP},</if>
<if test="commentAuthorAvatar != null">comment_author_avatar = #{commentAuthorAvatar},</if>
<if test="commentRole != null">comment_role = #{commentRole,jdbcType=INTEGER},</if>
<if test="commentUserId != null">comment_user_id = #{commentUserId,jdbcType=INTEGER},</if>
</set>
where comment_id = #{commentId,jdbcType=INTEGER}
</update>
<!-- 根据文章ID获取文章的所有评论 -->
<select id="listCommentByArticleId" resultType="com.liuyanzhao.ssm.blog.entity.Comment">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="tb"/>
WHERE
comment_article_id = #{id}
ORDER BY comment_id ASC
</select>
<!-- 获取评论列表支持根据用户ID过滤 -->
<select id="listComment" resultType="com.liuyanzhao.ssm.blog.entity.Comment">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="tb"/>
<where>
<if test="userId != null">
comment_user_id = #{userId}
</if>
</where>
ORDER BY comment_id DESC
</select>
<!-- 获取接收到的评论即根据一组文章ID获取对应的评论 -->
<select id="getReceiveComment" resultType="com.liuyanzhao.ssm.blog.entity.Comment">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="tb"/>
<where>
comment_article_id IN (
<foreach collection="list" item="item" separator=",">
#{item}
</foreach>
)
</where>
ORDER BY comment_id DESC
</select>
<!-- 统计总评论数 -->
<select id="countComment" parameterType="Integer" resultType="Integer">
SELECT count(*) FROM
<include refid="tb"/>
</select>
<!-- 获取最近评论支持根据用户ID过滤 -->
<select id="listRecentComment" parameterType="Integer" resultType="com.liuyanzhao.ssm.blog.entity.Comment">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="tb"/>
<where>
<if test="userId != null">
comment_user_id = #{userId}
</if>
</where>
ORDER BY comment_id DESC
LIMIT #{limit}
</select>
<!-- 获取某个评论的子评论列表 -->
<select id="listChildComment" resultType="com.liuyanzhao.ssm.blog.entity.Comment">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="tb"/>
WHERE
comment_pid=#{id}
</select>
</mapper>

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 定义了一个名为com.liuyanzhao.ssm.blog.mapper.LinkMapper的命名空间用于组织SQL语句 -->
<mapper namespace="com.liuyanzhao.ssm.blog.mapper.LinkMapper">
<!-- 定义了一个resultMap用于映射数据库列和Java对象属性 -->
<resultMap id="BaseResultMap" type="com.liuyanzhao.ssm.blog.entity.Link">
<id column="link_id" property="linkId" jdbcType="INTEGER"/> <!-- 链接ID -->
<result column="link_url" property="linkUrl" jdbcType="VARCHAR"/> <!-- 链接URL -->
<result column="link_name" property="linkName" jdbcType="VARCHAR"/> <!-- 链接名称 -->
<result column="link_image" property="linkImage" jdbcType="VARCHAR"/> <!-- 链接图片 -->
<result column="link_description" property="linkDescription" jdbcType="VARCHAR"/> <!-- 链接描述 -->
<result column="link_owner_nickname" property="linkOwnerNickname" jdbcType="VARCHAR"/> <!-- 链接所有者昵称 -->
<result column="link_owner_contact" property="linkOwnerContact" jdbcType="VARCHAR"/> <!-- 链接所有者联系方式 -->
<result column="link_update_time" property="linkUpdateTime" jdbcType="TIMESTAMP"/> <!-- 链接更新时间 -->
<result column="link_create_time" property="linkCreateTime" jdbcType="TIMESTAMP"/> <!-- 链接创建时间 -->
<result column="link_order" property="linkOrder" jdbcType="INTEGER"/> <!-- 链接排序 -->
<result column="link_status" property="linkStatus" jdbcType="INTEGER"/> <!-- 链接状态 -->
</resultMap>
<!-- 定义了一个SQL片段用于在其他SQL语句中引用列名 -->
<sql id="Base_Column_List">
link_id, link_url, link_name, link_image, link_description, link_owner_nickname,
link_owner_contact, link_update_time, link_create_time, link_order, link_status
</sql>
<!-- 定义了一个SQL片段用于在其他SQL语句中引用表名 -->
<sql id="tb">link</sql>
<!-- 根据ID获取链接 -->
<select id="getLinkById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List" />
from link
where link_id = #{linkId,jdbcType=INTEGER}
</select>
<!-- 根据ID删除链接 -->
<delete id="deleteById" parameterType="java.lang.Integer">
delete from link
where link_id = #{linkId,jdbcType=INTEGER}
</delete>
<!-- 插入一个新的链接 -->
<insert id="insert" parameterType="com.liuyanzhao.ssm.blog.entity.Link" useGeneratedKeys="true" keyProperty="linkId">
insert into link (link_id, link_url, link_name,
link_image, link_description, link_owner_nickname,
link_owner_contact, link_update_time, link_create_time,
link_order, link_status)
values (#{linkId,jdbcType=INTEGER}, #{linkUrl,jdbcType=VARCHAR}, #{linkName,jdbcType=VARCHAR},
#{linkImage,jdbcType=VARCHAR}, #{linkDescription,jdbcType=VARCHAR}, #{linkOwnerNickname,jdbcType=VARCHAR},
#{linkOwnerContact,jdbcType=VARCHAR}, #{linkUpdateTime,jdbcType=TIMESTAMP}, #{linkCreateTime,jdbcType=TIMESTAMP},
#{linkOrder,jdbcType=INTEGER}, #{linkStatus,jdbcType=INTEGER})
</insert>
<!-- 更新链接信息 -->
<update id="update" parameterType="com.liuyanzhao.ssm.blog.entity.Link">
update link
<set>
<if test="linkUrl != null" > link_url = #{linkUrl,jdbcType=VARCHAR},</if>
<if test="linkName != null" >link_name = #{linkName,jdbcType=VARCHAR},</if>
<if test="linkImage != null" >link_image = #{linkImage,jdbcType=VARCHAR},</if>
<if test="linkDescription != null" >link_description = #{linkDescription,jdbcType=VARCHAR},</if>
<if test="linkOwnerNickname != null" >link_owner_nickname = #{linkOwnerNickname,jdbcType=VARCHAR},</if>
<if test="linkOwnerContact != null" >link_owner_contact = #{linkOwnerContact,jdbcType=VARCHAR},</if>
<if test="linkUpdateTime != null" >link_update_time = #{linkUpdateTime,jdbcType=TIMESTAMP},</if>
<if test="linkCreateTime != null" >link_create_time = #{linkCreateTime,jdbcType=TIMESTAMP},</if>
<if test="linkOrder != null" >link_order = #{linkOrder,jdbcType=INTEGER}, </if>
<if test="linkStatus != null" >link_status = #{linkStatus,jdbcType=INTEGER},</if>
</set>
where link_id = #{linkId,jdbcType=INTEGER}
</update>
<!-- 获取链接总数 -->
<select id="countLink" resultType="Integer">
SELECT COUNT(*) FROM <include refid="tb"/>
<where>
<if test="status!=null">
link_status=#{status}
</if>
</where>
</select>
<!-- 获取链接列表 -->
<select id="listLink" resultType="com.liuyanzhao.ssm.blog.entity.Link">
SELECT
<include refid="Base_Column_List"/>
FROM <include refid="tb"/>
<where>
<if test="status!=null">
link_status=#{status}
</if>
</where>
ORDER BY link_status ASC,link_order DESC,link_id ASC
</select>
</mapper>

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.liuyanzhao.ssm.blog.mapper.MenuMapper">
<!-- 结果映射定义了Menu实体类与数据库表字段的对应关系 -->
<resultMap id="BaseResultMap" type="com.liuyanzhao.ssm.blog.entity.Menu">
<!-- 主键映射 -->
<id column="menu_id" property="menuId" jdbcType="INTEGER"/>
<!-- 普通字段映射 -->
<result column="menu_name" property="menuName" jdbcType="VARCHAR"/>
<result column="menu_url" property="menuUrl" jdbcType="VARCHAR"/>
<result column="menu_level" property="menuLevel" jdbcType="INTEGER"/>
<result column="menu_icon" property="menuIcon" jdbcType="VARCHAR"/>
<result column="menu_order" property="menuOrder" jdbcType="INTEGER"/>
</resultMap>
<!-- 基础字段列表 -->
<sql id="Base_Column_List">
menu_id, menu_name, menu_url, menu_level, menu_icon, menu_order
</sql>
<!-- 表名 -->
<sql id="tb">menu</sql>
<!-- 根据ID查询菜单 -->
<select id="getMenuById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"/>
from <include refid="tb"/>
where menu_id = #{menuId,jdbcType=INTEGER}
</select>
<!-- 根据ID删除菜单 -->
<delete id="deleteById" parameterType="java.lang.Integer">
delete from <include refid="tb"/>
where menu_id = #{menuId,jdbcType=INTEGER}
</delete>
<!-- 插入菜单 -->
<insert id="insert" parameterType="com.liuyanzhao.ssm.blog.entity.Menu" useGeneratedKeys="true" keyProperty="menuId">
insert into <include refid="tb"/>
(menu_id, menu_name, menu_url,
menu_level, menu_icon, menu_order)
values (#{menuId,jdbcType=INTEGER}, #{menuName,jdbcType=VARCHAR}, #{menuUrl,jdbcType=VARCHAR},
#{menuLevel,jdbcType=INTEGER}, #{menuIcon,jdbcType=VARCHAR}, #{menuOrder,jdbcType=INTEGER})
</insert>
<!-- 更新菜单 -->
<update id="update" parameterType="com.liuyanzhao.ssm.blog.entity.Menu">
update <include refid="tb"/>
<set>
<if test="menuName != null"> menu_name = #{menuName,jdbcType=VARCHAR},</if>
<if test="menuUrl != null">menu_url = #{menuUrl,jdbcType=VARCHAR},</if>
<if test="menuLevel != null">menu_level = #{menuLevel,jdbcType=INTEGER},</if>
<if test="menuIcon != null">menu_icon = #{menuIcon,jdbcType=VARCHAR},</if>
<if test="menuOrder != null">menu_order = #{menuOrder,jdbcType=INTEGER},</if>
</set>
where menu_id = #{menuId,jdbcType=INTEGER}
</update>
<!-- 获取菜单列表 -->
<select id="listMenu" resultType="com.liuyanzhao.ssm.blog.entity.Menu">
SELECT
<include refid="Base_Column_List"/>
FROM <include refid="tb"/>
ORDER BY menu_order DESC, menu_id ASC
</select>
</mapper>

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 定义了一个名为com.liuyanzhao.ssm.blog.mapper.NoticeMapper的命名空间用于组织SQL语句 -->
<mapper namespace="com.liuyanzhao.ssm.blog.mapper.NoticeMapper">
<!-- 定义了一个resultMap用于映射数据库列和Java对象属性 -->
<resultMap id="BaseResultMap" type="com.liuyanzhao.ssm.blog.entity.Notice">
<id column="notice_id" property="noticeId" jdbcType="INTEGER"/> <!-- 公告ID -->
<result column="notice_title" property="noticeTitle" jdbcType="VARCHAR"/> <!-- 公告标题 -->
<result column="notice_content" property="noticeContent" jdbcType="VARCHAR"/> <!-- 公告内容 -->
<result column="notice_create_time" property="noticeCreateTime" jdbcType="TIMESTAMP"/> <!-- 公告创建时间 -->
<result column="notice_update_time" property="noticeUpdateTime" jdbcType="TIMESTAMP"/> <!-- 公告更新时间 -->
<result column="notice_status" property="noticeStatus" jdbcType="INTEGER"/> <!-- 公告状态 -->
<result column="notice_order" property="noticeOrder" jdbcType="INTEGER"/> <!-- 公告排序 -->
</resultMap>
<!-- 定义了一个SQL片段用于在其他SQL语句中引用列名 -->
<sql id="Base_Column_List">
notice_id, notice_title, notice_content, notice_create_time, notice_update_time,
notice_status, notice_order
</sql>
<!-- 定义了一个SQL片段用于在其他SQL语句中引用表名 -->
<sql id="tb">notice</sql>
<!-- 根据ID获取公告 -->
<select id="getNoticeById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List" />
from <include refid="tb"/>
where notice_id = #{noticeId,jdbcType=INTEGER}
</select>
<!-- 根据ID删除公告 -->
<delete id="deleteById" parameterType="java.lang.Integer">
delete from <include refid="tb"/>
where notice_id = #{noticeId,jdbcType=INTEGER}
</delete>
<!-- 插入一个新的公告 -->
<insert id="insert" parameterType="com.liuyanzhao.ssm.blog.entity.Notice" useGeneratedKeys="true" keyProperty="noticeId">
insert into <include refid="tb"/>
(notice_id, notice_title, notice_content,
notice_create_time, notice_update_time,
notice_status, notice_order)
values (#{noticeId,jdbcType=INTEGER}, #{noticeTitle,jdbcType=VARCHAR}, #{noticeContent,jdbcType=VARCHAR},
#{noticeCreateTime,jdbcType=TIMESTAMP}, #{noticeUpdateTime,jdbcType=TIMESTAMP},
#{noticeStatus,jdbcType=INTEGER}, #{noticeOrder,jdbcType=INTEGER})
</insert>
<!-- 更新公告信息 -->
<update id="update" parameterType="com.liuyanzhao.ssm.blog.entity.Notice">
update <include refid="tb"/>
<set>
<if test="noticeTitle != null" > notice_title = #{noticeTitle,jdbcType=VARCHAR},</if>
<if test="noticeContent != null" >notice_content = #{noticeContent,jdbcType=VARCHAR},</if>
<if test="noticeCreateTime != null" >notice_create_time = #{noticeCreateTime,jdbcType=TIMESTAMP},</if>
<if test="noticeUpdateTime != null" >notice_update_time = #{noticeUpdateTime,jdbcType=TIMESTAMP},</if>
<if test="noticeStatus != null" >notice_status = #{noticeStatus,jdbcType=INTEGER},</if>
<if test="noticeOrder != null" >notice_order = #{noticeOrder,jdbcType=INTEGER},</if>
</set>
where notice_id = #{noticeId,jdbcType=INTEGER}
</update>
<!-- 根据主键更新公告信息 -->
<update id="updateByPrimaryKey" parameterType="com.liuyanzhao.ssm.blog.entity.Notice">
update <include refid="tb"/>
set notice_title = #{noticeTitle,jdbcType=VARCHAR},
notice_content = #{noticeContent,jdbcType=VARCHAR},
notice_create_time = #{noticeCreateTime,jdbcType=TIMESTAMP},
notice_update_time = #{noticeUpdateTime,jdbcType=TIMESTAMP},
notice_status = #{noticeStatus,jdbcType=INTEGER},
notice_order = #{noticeOrder,jdbcType=INTEGER}
where notice_id = #{noticeId,jdbcType=INTEGER}
</update>
<!-- 获取公告总数 -->
<select id="countNotice" resultType="Integer">
SELECT COUNT(*) FROM <include refid="tb"/>
<where>
<if test="status!=null">
notice_status=#{status}
</if>
</where>
</select>
<!-- 获取公告列表 -->
<select id="listNotice" resultType="com.liuyanzhao.ssm.blog.entity.Notice">
SELECT
<include refid="Base_Column_List"/>
FROM <include refid="tb"/>
<where>
<if test="status!=null">
notice_status=#{status}
</if>
</where>
ORDER BY notice_status ASC, notice_order DESC, notice_id ASC
</select>
</mapper>

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 定义了一个名为com.liuyanzhao.ssm.blog.mapper.OptionsMapper的命名空间用于组织SQL语句 -->
<mapper namespace="com.liuyanzhao.ssm.blog.mapper.OptionsMapper">
<!-- 定义了一个resultMap用于映射数据库列和Java对象属性 -->
<resultMap id="BaseResultMap" type="com.liuyanzhao.ssm.blog.entity.Options">
<id column="option_id" property="optionId" jdbcType="INTEGER"/> <!-- 选项ID -->
<result column="option_site_title" property="optionSiteTitle" jdbcType="VARCHAR"/> <!-- 网站标题 -->
<result column="option_site_descrption" property="optionSiteDescrption" jdbcType="VARCHAR"/> <!-- 网站描述 -->
<result column="option_meta_descrption" property="optionMetaDescrption" jdbcType="VARCHAR"/> <!-- Meta描述 -->
<result column="option_meta_keyword" property="optionMetaKeyword" jdbcType="VARCHAR"/> <!-- Meta关键词 -->
<result column="option_aboutsite_avatar" property="optionAboutsiteAvatar" jdbcType="VARCHAR"/> <!-- 关于页面头像 -->
<result column="option_aboutsite_title" property="optionAboutsiteTitle" jdbcType="VARCHAR"/> <!-- 关于页面标题 -->
<result column="option_aboutsite_content" property="optionAboutsiteContent" jdbcType="VARCHAR"/> <!-- 关于页面内容 -->
<result column="option_aboutsite_wechat" property="optionAboutsiteWechat" jdbcType="VARCHAR"/> <!-- 关于页面微信 -->
<result column="option_aboutsite_qq" property="optionAboutsiteQq" jdbcType="VARCHAR"/> <!-- 关于页面QQ -->
<result column="option_aboutsite_github" property="optionAboutsiteGithub" jdbcType="VARCHAR"/> <!-- 关于页面GitHub -->
<result column="option_aboutsite_weibo" property="optionAboutsiteWeibo" jdbcType="VARCHAR"/> <!-- 关于页面微博 -->
<result column="option_tongji" property="optionTongji" jdbcType="VARCHAR"/> <!-- 统计代码 -->
<result column="option_status" property="optionStatus" jdbcType="INTEGER"/> <!-- 网站状态 -->
</resultMap>
<!-- 定义了一个SQL片段用于在其他SQL语句中引用列名 -->
<sql id="Base_Column_List">
option_id, option_site_title, option_site_descrption, option_meta_descrption, option_meta_keyword,
option_aboutsite_avatar, option_aboutsite_title, option_aboutsite_content, option_aboutsite_wechat,
option_aboutsite_qq, option_aboutsite_github, option_aboutsite_weibo, option_tongji,
option_status
</sql>
<!-- 定义了一个SQL片段用于在其他SQL语句中引用表名 -->
<sql id="tb">options</sql>
<!-- 根据ID获取选项 -->
<select id="getOptionsById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"/>
from
<include refid="tb"/>
where option_id = #{optionId,jdbcType=INTEGER}
</select>
<!-- 根据ID删除选项 -->
<delete id="deleteById" parameterType="java.lang.Integer">
delete from
<include refid="tb"/>
where option_id = #{optionId,jdbcType=INTEGER}
</delete>
<!-- 插入一个新的选项 -->
<insert id="insert" parameterType="com.liuyanzhao.ssm.blog.entity.Options">
insert into
<include refid="tb"/>
(option_id, option_site_title, option_site_descrption,
option_meta_descrption, option_meta_keyword,
option_aboutsite_avatar, option_aboutsite_title,
option_aboutsite_content, option_aboutsite_wechat,
option_aboutsite_qq, option_aboutsite_github,
option_aboutsite_weibo, option_tongji, option_status
)
values (#{optionId,jdbcType=INTEGER}, #{optionSiteTitle,jdbcType=VARCHAR},
#{optionSiteDescrption,jdbcType=VARCHAR},
#{optionMetaDescrption,jdbcType=VARCHAR}, #{optionMetaKeyword,jdbcType=VARCHAR},
#{optionAboutsiteAvatar,jdbcType=VARCHAR}, #{optionAboutsiteTitle,jdbcType=VARCHAR},
#{optionAboutsiteContent,jdbcType=VARCHAR}, #{optionAboutsiteWechat,jdbcType=VARCHAR},
#{optionAboutsiteQq,jdbcType=VARCHAR}, #{optionAboutsiteGithub,jdbcType=VARCHAR},
#{optionAboutsiteWeibo,jdbcType=VARCHAR}, #{optionTongji,jdbcType=VARCHAR}, #{optionStatus,jdbcType=INTEGER}
)
</insert>
<!-- 更新选项信息 -->
<update id="update" parameterType="com.liuyanzhao.ssm.blog.entity.Options">
update
<include refid="tb"/>
<set>
<if test="optionSiteTitle != null">option_site_title = #{optionSiteTitle,jdbcType=VARCHAR},</if>
<if test="optionSiteDescrption != null">option_site_descrption = #{optionSiteDescrption,jdbcType=VARCHAR},</if>
<if test="optionMetaDescrption != null">option_meta_descrption = #{optionMetaDescrption,jdbcType=VARCHAR},</if>
<if test="optionMetaKeyword != null">option_meta_keyword = #{optionMetaKeyword,jdbcType=VARCHAR},</if>
<if test="optionAboutsiteAvatar != null">option_aboutsite_avatar = #{optionAboutsiteAvatar,jdbcType=VARCHAR},</if>
<if test="optionAboutsiteTitle != null">option_aboutsite_title = #{optionAboutsiteTitle,jdbcType=VARCHAR},</if>
<if test="optionAboutsiteContent != null">option_aboutsite_content = #{optionAboutsiteContent,jdbcType=VARCHAR},</if>
<if test="optionAboutsiteWechat != null">option_aboutsite_wechat = #{optionAboutsiteWechat,jdbcType=VARCHAR},</if>
<if test="optionAboutsiteQq != null">option_aboutsite_qq = #{optionAboutsiteQq,jdbcType=VARCHAR},</if>
<if test="optionAboutsiteGithub != null">option_aboutsite_github = #{optionAboutsiteGithub,jdbcType=VARCHAR},</if>
<if test="optionAboutsiteWeibo != null">option_aboutsite_weibo = #{optionAboutsiteWeibo,jdbcType=VARCHAR},</if>
<if test="optionTongji != null">option_tongji = #{optionTongji,jdbcType=VARCHAR},</if>
<if test="optionStatus != null">option_status = #{optionStatus,jdbcType=INTEGER}</if>
</set>
where option_id = #{optionId,jdbcType=INTEGER}
</update>
<!-- 获取全局选项 -->
<select id="getOptions" resultType="com.liuyanzhao.ssm.blog.entity.Options">
SELECT * FROM
<include refid="tb"/>
limit 1
</select>
</mapper>

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 由于网络原因,上述链接可能无法成功解析。请检查链接的合法性或稍后再试。 -->
<mapper namespace="com.liuyanzhao.ssm.blog.mapper.PageMapper">
<!-- 定义数据库列与实体属性的映射关系 -->
<resultMap id="BaseResultMap" type="com.liuyanzhao.ssm.blog.entity.Page">
<id column="page_id" property="pageId" jdbcType="INTEGER"/> <!-- 页面ID -->
<result column="page_key" property="pageKey" jdbcType="VARCHAR"/> <!-- 页面关键字 -->
<result column="page_title" property="pageTitle" jdbcType="VARCHAR"/> <!-- 页面标题 -->
<result column="page_content" property="pageContent" jdbcType="VARCHAR"/> <!-- 页面内容 -->
<result column="page_create_time" property="pageCreateTime" jdbcType="TIMESTAMP"/> <!-- 页面创建时间 -->
<result column="page_update_time" property="pageUpdateTime" jdbcType="TIMESTAMP"/> <!-- 页面更新时间 -->
<result column="page_view_count" property="pageViewCount" jdbcType="INTEGER"/> <!-- 页面浏览次数 -->
<result column="page_comment_count" property="pageCommentCount" jdbcType="INTEGER"/> <!-- 页面评论次数 -->
<result column="page_status" property="pageStatus" jdbcType="INTEGER"/> <!-- 页面状态 -->
</resultMap>
<!-- 定义列名的SQL片段 -->
<sql id="Base_Column_List">
page_id, page_key, page_title, page_content, page_create_time, page_update_time,
page_view_count, page_comment_count, page_status
</sql>
<!-- 定义表名的SQL片段 -->
<sql id="tb">page</sql>
<!-- 根据ID查询页面 -->
<select id="getPageById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List" />
from <include refid="tb"/>
where page_id = #{pageId,jdbcType=INTEGER}
</select>
<!-- 根据ID删除页面 -->
<delete id="deleteById" parameterType="java.lang.Integer">
delete from <include refid="tb"/>
where page_id = #{pageId,jdbcType=INTEGER}
</delete>
<!-- 插入新的页面 -->
<insert id="insert" parameterType="com.liuyanzhao.ssm.blog.entity.Page" useGeneratedKeys="true" keyProperty="pageId">
insert into <include refid="tb"/>
(page_id, page_key, page_title,
page_content, page_create_time, page_update_time,
page_view_count, page_comment_count, page_status
)
values (#{pageId,jdbcType=INTEGER}, #{pageKey,jdbcType=VARCHAR}, #{pageTitle,jdbcType=VARCHAR},
#{pageContent,jdbcType=VARCHAR}, #{pageCreateTime,jdbcType=TIMESTAMP}, #{pageUpdateTime,jdbcType=TIMESTAMP},
#{pageViewCount,jdbcType=INTEGER}, #{pageCommentCount,jdbcType=INTEGER}, #{pageStatus,jdbcType=INTEGER}
)
</insert>
<!-- 更新页面信息 -->
<update id="update" parameterType="com.liuyanzhao.ssm.blog.entity.Page">
update <include refid="tb"/>
<set>
<if test="pageKey != null" > page_key = #{pageKey,jdbcType=VARCHAR},</if>
<if test="pageTitle != null" >page_title = #{pageTitle,jdbcType=VARCHAR},</if>
<if test="pageContent != null" >page_content = #{pageContent,jdbcType=VARCHAR},</if>
<if test="pageCreateTime != null" >page_create_time = #{pageCreateTime,jdbcType=TIMESTAMP},</if>
<if test="pageUpdateTime != null" >page_update_time = #{pageUpdateTime,jdbcType=TIMESTAMP},</if>
<if test="pageViewCount != null" >page_view_count = #{pageViewCount,jdbcType=INTEGER},</if>
<if test="pageCommentCount != null" >page_comment_count = #{pageCommentCount,jdbcType=INTEGER},</if>
<if test="pageStatus != null" >page_status = #{pageStatus,jdbcType=INTEGER}</if>
</set>
where page_id = #{pageId,jdbcType=INTEGER}
</update>
<!-- 获取页面列表,支持根据状态过滤 -->
<select id="listPage" resultType="com.liuyanzhao.ssm.blog.entity.Page">
SELECT
<include refid="Base_Column_List"/>
FROM <include refid="tb"/>
<where>
<if test="status!=null">
page_status=#{status}
</if>
</where>
</select>
<!-- 根据关键字获取页面 -->
<select id="getPageByKey" resultType="com.liuyanzhao.ssm.blog.entity.Page">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="tb"/>
<where>
<if test="status!=null">
page_status=#{status} AND
</if>
page_key=#{key}
</where>
</select>
</mapper>

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 由于网络原因,上述链接可能无法成功解析。请检查链接的合法性或稍后再试。 -->
<mapper namespace="com.liuyanzhao.ssm.blog.mapper.TagMapper">
<!-- 定义数据库列与实体属性的映射关系 -->
<resultMap id="BaseResultMap" type="com.liuyanzhao.ssm.blog.entity.Tag">
<id column="tag_id" property="tagId" jdbcType="INTEGER"/> <!-- 标签ID -->
<result column="tag_name" property="tagName" jdbcType="VARCHAR"/> <!-- 标签名称 -->
<result column="tag_description" property="tagDescription" jdbcType="VARCHAR"/> <!-- 标签描述 -->
</resultMap>
<!-- 定义列名的SQL片段 -->
<sql id="Base_Column_List">
tag_id, tag_name, tag_description
</sql>
<!-- 定义表名的SQL片段 -->
<sql id="tb">tag</sql>
<!-- 根据ID查询标签 -->
<select id="getTagById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List" />
from <include refid="tb"/>
where tag_id = #{tagId,jdbcType=INTEGER}
</select>
<!-- 根据ID删除标签 -->
<delete id="deleteById" parameterType="java.lang.Integer">
delete from <include refid="tb"/>
where tag_id = #{tagId,jdbcType=INTEGER}
</delete>
<!-- 插入新的标签 -->
<insert id="insert" parameterType="com.liuyanzhao.ssm.blog.entity.Tag" useGeneratedKeys="true" keyProperty="tagId">
insert into <include refid="tb"/>
(tag_name, tag_description)
values (#{tagName,jdbcType=VARCHAR}, #{tagDescription,jdbcType=VARCHAR})
</insert>
<!-- 更新标签信息 -->
<update id="update" parameterType="com.liuyanzhao.ssm.blog.entity.Tag">
update <include refid="tb"/>
<set>
<if test="tagName != null">
tag_name = #{tagName,jdbcType=VARCHAR},
</if>
<if test="tagDescription != null">
tag_description = #{tagDescription,jdbcType=VARCHAR}
</if>
</set>
where tag_id = #{tagId,jdbcType=INTEGER}
</update>
<!-- 获取所有标签列表 -->
<select id="listTag" resultType="com.liuyanzhao.ssm.blog.entity.Tag">
SELECT
<include refid="Base_Column_List"/>
FROM <include refid="tb"/>
</select>
<!-- 获取标签总数 -->
<select id="countTag" resultType="Integer">
SELECT COUNT(*) FROM <include refid="tb"/>
</select>
<!-- 根据标签名获取标签 -->
<select id="getTagByName" parameterType="String" resultType="com.liuyanzhao.ssm.blog.entity.Tag">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="tb"/>
WHERE tag_name=#{value}
limit 1
</select>
</mapper>

@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 由于网络原因,上述链接可能无法成功解析。请检查链接的合法性或稍后再试。 -->
<mapper namespace="com.liuyanzhao.ssm.blog.mapper.UserMapper">
<!-- 定义数据库列与实体属性的映射关系 -->
<resultMap id="BaseResultMap" type="com.liuyanzhao.ssm.blog.entity.User">
<id column="user_id" property="userId" jdbcType="INTEGER"/> <!-- 用户ID -->
<result column="user_name" property="userName" jdbcType="VARCHAR"/> <!-- 用户名 -->
<result column="user_pass" property="userPass" jdbcType="VARCHAR"/> <!-- 用户密码 -->
<result column="user_nickname" property="userNickname" jdbcType="VARCHAR"/> <!-- 用户昵称 -->
<result column="user_email" property="userEmail" jdbcType="VARCHAR"/> <!-- 用户邮箱 -->
<result column="user_url" property="userUrl" jdbcType="VARCHAR"/> <!-- 用户个人网址 -->
<result column="user_avatar" property="userAvatar" jdbcType="VARCHAR"/> <!-- 用户头像 -->
<result column="user_last_login_ip" property="userLastLoginIp" jdbcType="VARCHAR"/> <!-- 用户最后登录IP -->
<result column="user_register_time" property="userRegisterTime" jdbcType="TIMESTAMP"/> <!-- 用户注册时间 -->
<result column="user_last_login_time" property="userLastLoginTime" jdbcType="TIMESTAMP"/> <!-- 用户最后登录时间 -->
<result column="user_status" property="userStatus" jdbcType="INTEGER"/> <!-- 用户状态 -->
<result column="user_role" property="userRole" jdbcType="VARCHAR"/> <!-- 用户角色 -->
</resultMap>
<!-- 定义表名的SQL片段 -->
<sql id="tb">user</sql>
<!-- 定义列名的SQL片段 -->
<sql id="Base_Column_List">
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_role
</sql>
<!-- 根据ID查询用户 -->
<select id="getUserById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"/>
from <include refid="tb"/>
where user_id = #{userId,jdbcType=INTEGER}
</select>
<!-- 根据ID删除用户 -->
<delete id="deleteById" parameterType="java.lang.Integer">
delete from
<include refid="tb"/>
where user_id = #{userId,jdbcType=INTEGER}
</delete>
<!-- 插入新用户 -->
<insert id="insert" parameterType="com.liuyanzhao.ssm.blog.entity.User" useGeneratedKeys="true" keyProperty="userId">
insert into
<include refid="tb"/>
(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_role)
values (#{userId,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{userPass,jdbcType=VARCHAR},
#{userNickname,jdbcType=VARCHAR}, #{userEmail,jdbcType=VARCHAR}, #{userUrl,jdbcType=VARCHAR},
#{userAvatar,jdbcType=VARCHAR}, #{userLastLoginIp,jdbcType=VARCHAR}, #{userRegisterTime,jdbcType=TIMESTAMP},
#{userLastLoginTime,jdbcType=TIMESTAMP}, #{userStatus,jdbcType=INTEGER}, #{userRole,jdbcType=VARCHAR})
</insert>
<!-- 更新用户信息 -->
<update id="update" parameterType="com.liuyanzhao.ssm.blog.entity.User">
update
<include refid="tb"/>
<set>
<if test="userName != null">user_name = #{userName,jdbcType=VARCHAR},</if>
<if test="userPass != null">user_pass = #{userPass,jdbcType=VARCHAR},</if>
<if test="userNickname != null">user_nickname = #{userNickname,jdbcType=VARCHAR},</if>
<if test="userEmail != null">user_email = #{userEmail,jdbcType=VARCHAR},</if>
<if test="userUrl != null">user_url = #{userUrl,jdbcType=VARCHAR},</if>
<if test="userAvatar != null">user_avatar = #{userAvatar,jdbcType=VARCHAR},</if>
<if test="userLastLoginIp != null">user_last_login_ip = #{userLastLoginIp,jdbcType=VARCHAR},</if>
<if test="userRegisterTime != null">user_register_time = #{userRegisterTime,jdbcType=TIMESTAMP},</if>
<if test="userLastLoginTime != null">user_last_login_time = #{userLastLoginTime,jdbcType=TIMESTAMP},</if>
<if test="userStatus != null">user_status = #{userStatus,jdbcType=INTEGER},</if>
<if test="userRole != null">user_role = #{userRole,jdbcType=VARCHAR},</if>
</set>
where user_id = #{userId,jdbcType=INTEGER}
</update>
<!-- 查询用户列表 -->
<select id="listUser" parameterType="com.liuyanzhao.ssm.blog.entity.User"
resultType="com.liuyanzhao.ssm.blog.entity.User">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="tb"/>
ORDER BY `user_status` ASC
</select>
<!-- 根据用户名或邮箱获取用户 -->
<select id="getUserByNameOrEmail" parameterType="String" resultType="com.liuyanzhao.ssm.blog.entity.User">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="tb"/>
<where>
user_name=#{value} OR user_email=#{value}
</where>
AND user_status>0
limit 1
</select>
<!-- 根据用户名获取用户 -->
<select id="getUserByName" parameterType="String" resultType="com.liuyanzhao.ssm.blog.entity.User">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="tb"/>
<where>
user_name=#{value}
</where>
limit 1
</select>
<!-- 根据邮箱获取用户 -->
<select id="getUserByEmail" parameterType="String" resultType="com.liuyanzhao.ssm.blog.entity.User">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="tb"/>
<where>
user_email=#{value}
</where>
limit 1
</select>
</mapper>

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 全局配置 -->
<settings>
<!--允许 JDBC 支持自动生成主键-->
<setting name="useGeneratedKeys" value="false"/>
<!--是否开启自动驼峰命名规则camel case映射即从经典数据库列名 A_COLUMN 到经典
Java 属性名 aColumn 的类似映射。 -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
<!-- 打印查询语句 -->
<!-- <setting name="logImpl" value="STDOUT_LOGGING" />-->
</settings>
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<!--<property name="dialect" value="mysql"/>-->
<property name="offsetAsPageNum" value="false"/>
<property name="rowBoundsWithCount" value="false"/>
<property name="pageSizeZero" value="true"/>
<property name="reasonable" value="true"/>
<property name="supportMethodsArguments" value="false"/>
<property name="returnPageInfo" value="none"/>
</plugin>
</plugins>
</configuration>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save