一、项目简述
系统功能:
后台登录密码为admin密码123456 文章的发表,分类,评论,收搜索,后台管理的的文章新 增,分类新增,评论审核,标签管理,评论管理,分类管 理,博客管理,系统管理等等功能。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +Springboot+ SpringMVC + MyBatis + ThymeLeaf + HTML+ JavaScript + JQuery + Ajax + maven等等
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
request.getSession().removeAttribute("errorMsg");
return "admin/login";
}
}
博客信息控制层:
/**
* 博客控制层
*/
@Controller
@RequestMapping("/admin")
public class BlogController {
@Resource
private BlogService blogService;
@Resource
private CategoryService categoryService;
/**
* 博客列表
*
* @param params 参数
* @return com.hbu.myblog.util.Result
*/
@GetMapping("/blogs/list")
*
* @param request http请求
* @return java.lang.String
*/
@GetMapping("/profile")
public String profile(HttpServletRequest request) {
Integer loginUserId = (int) request.getSession().getAttribute("loginUserId");
AdminUser adminUser = adminUserService.getUserDetailById(loginUserId);
if (adminUser == null) {
return "admin/login";
}
request.setAttribute("path", "profile");
request.setAttribute("loginUserName", adminUser.getLoginUserName());
request.setAttribute("nickName", adminUser.getNickName());
return "admin/profile";
}
/**
* 修改密码
*
* @param request http请求
* @param originalPassword 原始密码
* @param newPassword 新密码
* @return java.lang.String
if (adminUserService.updateName(loginUserId, loginUserName, nickName)) {
return "success";
} else {
return "修改失败";
}
}
/**
* 管理员退出
*
* @param request http请求
* @return java.lang.String
*/
@GetMapping("/logout")
public String logout(HttpServletRequest request) {
request.getSession().removeAttribute("loginUserId");
request.getSession().removeAttribute("loginUser");
request.getSession().removeAttribute("errorMsg");
return "admin/login";
}
}
博客信息控制层:
/**
* 博客控制层
*/
@Controller
@RequestMapping("/admin")
session.setAttribute("loginUserId", adminUser.getAdminUserId());
//session过期时间设置为7200秒 即两小时
//session.setMaxInactiveInterval(60 * 60 * 2);
return "redirect:/admin/index";
} else {
session.setAttribute("errorMsg", "登陆失败");
return "admin/login";
}
}
/**
* 修改个人信息
*
* @param request http请求
* @return java.lang.String
*/
@GetMapping("/profile")
public String profile(HttpServletRequest request) {
Integer loginUserId = (int) request.getSession().getAttribute("loginUserId");
AdminUser adminUser = adminUserService.getUserDetailById(loginUserId);
if (adminUser == null) {
return "admin/login";
}
request.setAttribute("path", "profile");
request.setAttribute("loginUserName", adminUser.getLoginUserName());
}
/**
* @param categoryId
* @param categoryName
* @param categoryIcon
* @return com.hbu.myblog.util.Result
*/
@RequestMapping(value = "/categories/update", method = RequestMethod.POST)
@ResponseBody
public Result update(@RequestParam("categoryId") Integer categoryId,
@RequestParam("categoryName") String categoryName,
@RequestParam("categoryIcon") String categoryIcon) {
if (StringUtils.isEmpty(categoryName)) {
return ResultGenerator.genFailResult("请输入分类名称!");
}
/**
* 管理员退出
*
* @param request http请求
* @return java.lang.String
*/
@GetMapping("/logout")
public String logout(HttpServletRequest request) {
request.getSession().removeAttribute("loginUserId");
request.getSession().removeAttribute("loginUser");
request.getSession().removeAttribute("errorMsg");
return "admin/login";
}
}
博客信息控制层:
/**
@RequestParam("categoryIcon") String categoryIcon) {
if (StringUtils.isEmpty(categoryName)) {
return ResultGenerator.genFailResult("请输入分类名称!");
}
if (StringUtils.isEmpty(categoryIcon)) {
return ResultGenerator.genFailResult("请选择分类图标!");
}
if (categoryService.updateCategory(categoryId, categoryName, categoryIcon)) {
return ResultGenerator.genSuccessResult();
} else {
return ResultGenerator.genFailResult("分类名称重复");
}
}
/**
* @param ids
* @return com.hbu.myblog.util.Result
*/
@RequestMapping(value = "/categories/delete", method = RequestMethod.POST)
@ResponseBody
public Result delete(@RequestBody Integer[] ids) {
@ResponseBody
public Result update(@RequestParam("blogId") Long blogId,
@RequestParam("blogTitle") String blogTitle,
@RequestParam(name = "blogSummary", required = false) String blogSummary,
@RequestParam("blogCategoryId") Integer blogCategoryId,
@RequestParam("blogTags") String blogTags,
@RequestParam("blogContent") String blogContent,
@RequestParam("blogStatus") Byte blogStatus,
@RequestParam("enableComment") Byte enableComment) {
if (StringUtils.isEmpty(blogTitle)) {
return ResultGenerator.genFailResult("请输入文章标题");
}
if (blogTitle.trim().length() > 150) {
return ResultGenerator.genFailResult("标题过长");
}
request.setAttribute("commentCount", commentService.getTotalComments());
return "admin/index";
}
/**
* 登录界面
*
* @param userName 用户名
* @param password 密码
* @param verifyCode 验证码
* @param session session
* @return java.lang.String
*/
@PostMapping(value = "/login")
public String login(@RequestParam("userName") String userName,
@RequestParam("password") String password,
@RequestParam("verifyCode") String verifyCode,
HttpSession session) {
if (StringUtils.isEmpty(verifyCode)) {
session.setAttribute("errorMsg", "验证码不能为空");
return "admin/login";
}
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)) {
@Controller
@RequestMapping("/admin")
public class AdminController {
@Resource
private AdminUserService adminUserService;
@Resource
private BlogService blogService;
@Resource
private CategoryService categoryService;
@Resource
private TagService tagService;
@Resource
private CommentService commentService;
/**
* 处理登录请求
*
* @return java.lang.String
*/