源码获取:博客首页 "资源" 里下载!
本系统分为管理员、游客两种角色;
管理员角色包含以下功能:
登录,用户增删改查,文章增删改查,链接增删改查,日志查看,查看近期数据,类别管理等功能。
游客角色包含以下功能:
首页,查看文章,注册账号,登录,管理自己写的文章,管理自己的文章,评论文章等功能。
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目:是;
1. 后端:SpringBoot
2. 前端:JSP+CSS+JavaScript+LayUI
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入http://localhost:8090/ 登录
/**
* @author yy
*/
@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")
@ResponseBody
public Result list(@RequestParam Map params) {
if (StringUtils.isEmpty(params.get("page")) || StringUtils.isEmpty(params.get("limit"))) {
return ResultGenerator.genFailResult("参数异常!");
}
PageQueryUtil pageUtil = new PageQueryUtil(params);
return ResultGenerator.genSuccessResult(blogService.getBlogsPage(pageUtil));
}
/**
* @param request http请求
* @return java.lang.String
*/
@GetMapping("/blogs")
public String list(HttpServletRequest request) {
request.setAttribute("path", "blogs");
return "admin/blog";
}
/**
* @param request http请求
* @return java.lang.String
*/
@GetMapping("/blogs/edit")
public String edit(HttpServletRequest request) {
request.setAttribute("path", "edit");
request.setAttribute("categories", categoryService.getAllCategories());
return "admin/edit";
}
/**
* @param request http请求
* @param blogId 博客id
* @return java.lang.String
*/
@GetMapping("/blogs/edit/{blogId}")
public String edit(HttpServletRequest request, @PathVariable("blogId") Long blogId) {
request.setAttribute("path", "edit");
Blog blog = blogService.getBlogById(blogId);
if (blog == null) {
return "error/error_400";
}
request.setAttribute("blog", blog);
request.setAttribute("categories", categoryService.getAllCategories());
return "admin/edit";
}
/**
* 添加文章
*
* @param blogTitle 文章标题
* @param blogSummary 摘要
* @param blogCategoryId 类别
* @param blogTags 标签
* @param blogContent 内容
* @param blogStatus 草稿,发布
* @param enableComment 可否评论
* @return com.hbu.myblog.util.Result
*/
@PostMapping("/blogs/save")
@ResponseBody
public Result save(@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("标题过长");
}
if (StringUtils.isEmpty(blogTags)) {
return ResultGenerator.genFailResult("请输入文章标签");
}
if (blogTags.trim().length() > 150) {
return ResultGenerator.genFailResult("标签过长");
}
if (blogSummary.trim().length() > 375) {
return ResultGenerator.genFailResult("摘要过长");
}
if (StringUtils.isEmpty(blogContent)) {
return ResultGenerator.genFailResult("请输入文章内容");
}
if (blogTags.trim().length() > 100000) {
return ResultGenerator.genFailResult("文章内容过长");
}
Blog blog = new Blog();
blog.setBlogTitle(blogTitle);
blog.setBlogSummary(blogSummary);
blog.setBlogCategoryId(blogCategoryId);
blog.setBlogTags(blogTags);
blog.setBlogContent(blogContent);
blog.setBlogStatus(blogStatus);
blog.setEnableComment(enableComment);
String saveBlogResult = blogService.saveBlog(blog);
if ("success".equals(saveBlogResult)) {
return ResultGenerator.genSuccessResult("添加成功");
} else {
return ResultGenerator.genFailResult(saveBlogResult);
}
}
/**
* 修改文章
*
* @param blogId 文章ID
* @param blogTitle 文章标题
* @param blogSummary 摘要
* @param blogCategoryId 类别
* @param blogTags 标签
* @param blogContent 内容
* @param blogStatus 草稿,发布
* @param enableComment 可否评论
* @return com.hbu.myblog.util.Result
*/
@PostMapping("/blogs/update")
@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("标题过长");
}
if (StringUtils.isEmpty(blogTags)) {
return ResultGenerator.genFailResult("请输入文章标签");
}
if (blogTags.trim().length() > 150) {
return ResultGenerator.genFailResult("标签过长");
}
if (blogSummary.trim().length() > 375) {
return ResultGenerator.genFailResult("摘要过长");
}
if (StringUtils.isEmpty(blogContent)) {
return ResultGenerator.genFailResult("请输入文章内容");
}
if (blogTags.trim().length() > 100000) {
return ResultGenerator.genFailResult("文章内容过长");
}
Blog blog = new Blog();
blog.setBlogId(blogId);
blog.setBlogTitle(blogTitle);
blog.setBlogSummary(blogSummary);
blog.setBlogCategoryId(blogCategoryId);
blog.setBlogTags(blogTags);
blog.setBlogContent(blogContent);
blog.setBlogStatus(blogStatus);
blog.setEnableComment(enableComment);
String updateBlogResult = blogService.updateBlog(blog);
if ("success".equals(updateBlogResult)) {
return ResultGenerator.genSuccessResult("修改成功");
} else {
return ResultGenerator.genFailResult(updateBlogResult);
}
}
/**
* 根据id的之删除文章
*
* @param ids 要删除文章id列表
* @return com.hbu.myblog.util.Result
*/
@PostMapping("/blogs/delete")
@ResponseBody
public Result delete(@RequestBody Integer[] ids) {
if (ids.length < 1) {
return ResultGenerator.genFailResult("参数异常!");
}
if (blogService.deleteBatch(ids)) {
return ResultGenerator.genSuccessResult();
} else {
return ResultGenerator.genFailResult("删除失败");
}
}
}
@Controller
@RequestMapping("/admin")
public class CategoryController {
@Resource
private CategoryService categoryService;
/**
* @param request
* @return java.lang.String
*/
@GetMapping("/categories")
public String categoryPage(HttpServletRequest request) {
request.setAttribute("path", "categories");
return "admin/category";
}
/**
* @param params
* @return com.hbu.myblog.util.Result
*/
@RequestMapping(value = "/categories/list", method = RequestMethod.GET)
@ResponseBody
public Result list(@RequestParam Map params) {
if (StringUtils.isEmpty(params.get("page")) || StringUtils.isEmpty(params.get("limit"))) {
return ResultGenerator.genFailResult("参数异常!");
}
PageQueryUtil pageUtil = new PageQueryUtil(params);
return ResultGenerator.genSuccessResult(categoryService.getBlogCategoryPage(pageUtil));
}
/**
* @param categoryName
* @param categoryIcon
* @return com.hbu.myblog.util.Result
*/
@RequestMapping(value = "/categories/save", method = RequestMethod.POST)
@ResponseBody
public Result save(@RequestParam("categoryName") String categoryName,
@RequestParam("categoryIcon") String categoryIcon) {
if (StringUtils.isEmpty(categoryName)) {
return ResultGenerator.genFailResult("请输入分类名称!");
}
if (StringUtils.isEmpty(categoryIcon)) {
return ResultGenerator.genFailResult("请选择分类图标!");
}
if (categoryService.saveCategory(categoryName, categoryIcon)) {
return ResultGenerator.genSuccessResult();
} else {
return ResultGenerator.genFailResult("分类名称重复");
}
}
/**
* @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("请输入分类名称!");
}
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) {
if (ids.length < 1) {
return ResultGenerator.genFailResult("参数异常!");
}
if (categoryService.deleteBatch(ids)) {
return ResultGenerator.genSuccessResult();
} else {
return ResultGenerator.genFailResult("删除失败");
}
}
}
@Controller
@RequestMapping("/admin")
public class TagController {
@Resource
private TagService tagService;
/**
* @param request
* @return java.lang.String
*/
@GetMapping("/tags")
public String tagPage(HttpServletRequest request) {
request.setAttribute("path", "tags");
return "admin/tag";
}
/**
* @param params
* @return com.hbu.myblog.util.Result
*/
@GetMapping("/tags/list")
@ResponseBody
public Result list(@RequestParam Map params) {
if (StringUtils.isEmpty(params.get("page")) || StringUtils.isEmpty(params.get("limit"))) {
return ResultGenerator.genFailResult("参数异常!");
}
PageQueryUtil pageUtil = new PageQueryUtil(params);
return ResultGenerator.genSuccessResult(tagService.getBlogTagPage(pageUtil));
}
/**
* @param tagName
* @return com.hbu.myblog.util.Result
*/
@PostMapping("/tags/save")
@ResponseBody
public Result save(@RequestParam("tagName") String tagName) {
if (StringUtils.isEmpty(tagName)) {
return ResultGenerator.genFailResult("参数异常!");
}
if (tagService.saveTag(tagName)) {
return ResultGenerator.genSuccessResult();
} else {
return ResultGenerator.genFailResult("标签名称重复");
}
}
@PostMapping("/tags/delete")
@ResponseBody
public Result delete(@RequestBody Integer[] ids) {
if (ids.length < 1) {
return ResultGenerator.genFailResult("参数异常!");
}
if (tagService.deleteBatch(ids)) {
return ResultGenerator.genSuccessResult();
} else {
return ResultGenerator.genFailResult("有关联数据请勿强行删除");
}
}
}
源码获取:博客首页 "资源" 里下载!