Compare commits
43 Commits
@ -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">{
|
||||||
|
"associatedIndex": 7
|
||||||
|
}</component>
|
||||||
|
<component name="ProjectId" id="2pkoas9hD1WLgDh1lyVWy1g01SE" />
|
||||||
|
<component name="ProjectViewState">
|
||||||
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
|
<option name="showLibraryContents" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="PropertiesComponent">{
|
||||||
|
"keyToString": {
|
||||||
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
|
"git-widget-placeholder": "develop",
|
||||||
|
"kotlin-language-version-configured": "true",
|
||||||
|
"last_opened_file_path": "D:/下载/ForestBlog-master",
|
||||||
|
"node.js.detected.package.eslint": "true",
|
||||||
|
"node.js.detected.package.tslint": "true",
|
||||||
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
|
"nodejs_package_manager_path": "npm",
|
||||||
|
"vue.rearranger.settings.migration": "true"
|
||||||
|
}
|
||||||
|
}</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,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,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,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,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,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,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,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);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据文章ID查询分类ID
|
||||||
|
*
|
||||||
|
* @param articleId 文章ID
|
||||||
|
* @return 分类ID列表
|
||||||
|
*/
|
||||||
|
List<Integer> selectCategoryIdByArticleId(Integer articleId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分类ID查询文章ID
|
||||||
|
*
|
||||||
|
* @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,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,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,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,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>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue