基于javaweb的个人博客系统(java+springboot+springsecurity+thymeleaf+mysql)

基于javaweb的个人博客系统(java+springboot+springsecurity+thymeleaf+mysql)

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

20220819210609

20220819210610

20220819210612

20220819210613

20220819210614

20220819210615

20220819210616

基于javaweb+mysql的个人博客系统(java+SpringBoot+SpringSecurity+Thymeleaf+Mysql)

项目介绍

本系统是一个个人博客的管理系统,用户可以注册账号并登陆系统查看发布的文章并进行阅读评论等 本系统主要有三种用户: 1、游客角色主要功能: 没有登陆的用户,可以查询文章,但是无法进行评论,系统中的所有文章可以通过内容搜索,可以通过分类搜索也可以通过标签就行搜索 2、注册用户主要功能 可以对所有的文章进行阅读以及评论等功能,可以对文章进行赞赏(支付宝或者微信付钱) 3、管理员主要功能: 拥有注册用户的所有权限,管理分类以及发布文章和管理标签等,友链管理,时间轴管理等

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;  4.数据库:MySql 5.7版本; 5.是否Maven项目:是;

技术栈

SpringBoot+SpringSecurity+Mybatis+Mysql+Redis+Thymeleaf+JQuery

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application.yml配置文件中的数据库配置改为自己的配置; 4. 运行项目,项目运行成功后,访问地址localhost:8080 管理员账号密码:zhangpeng98aliyun.com/mt2680324 用户账号密码:zhangpengaliyun.com/mt2680324

管理员控制层:

@Controller

@RequestMapping(“/admin/blog”)

public class AdminBlogController {

@Autowired

private BlogService blogService;

@Autowired

private TypeService typeService;

@Autowired

private TagService tagService;

@RequestMapping(“/showAll”)

public ModelAndView showAll(@RequestParam(name = “pageNum”, required = false, defaultValue = “1”) Integer pageNum,

@RequestParam(name = “pageSize”, required = false, defaultValue = “5”) Integer pageSize,

@RequestParam(name = “title”, required = false, defaultValue = “”) String title,

@RequestParam(name = “typeId”, required = false, defaultValue = “0”) Integer typeId,

@RequestParam(name = “recommend”, required = false, defaultValue = “false”) Boolean recommend) {

if (recommend == false) {

recommend = null;

ModelAndView mv = new ModelAndView ();

//展示所有博客前查询所有类别

List types = typeService.selectAll ();

mv.addObject (“types”, types);

//调用业务层方法

List blogs = blogService.selectAll (pageNum, pageSize, title, typeId, recommend);

PageInfo pageInfo = new PageInfo<> (blogs, 5);

mv.addObject (“pageInfo”, pageInfo);

mv.addObject (“title”, title);

mv.addObject (“typeId”, typeId);

mv.addObject (“recommend”, recommend);

mv.setViewName (“admin/blogs”);

return mv;

@RequestMapping(“/showAll/search”)

public String search(@RequestParam(name = “pageNum”, required = false, defaultValue = “1”) Integer pageNum,

@RequestParam(name = “pageSize”, required = false, defaultValue = “5”) Integer pageSize,

@RequestParam(name = “title”, required = false, defaultValue = “”) String title,

@RequestParam(name = “typeId”, required = false, defaultValue = “0”) Integer typeId,

@RequestParam(name = “recommend”, required = false, defaultValue = “false”) Boolean recommend,

Model model) {

if (recommend == false) {

recommend = null;

//调用业务层方法

List blogs = blogService.selectAll (pageNum, pageSize, title, typeId, recommend);

PageInfo pageInfo = new PageInfo<> (blogs, 5);

model.addAttribute (“pageInfo”, pageInfo);

return “admin/blogs::blogList”;

@RequestMapping(“/toAdd”)

public String toAdd(Model model) {

//添加博客页前展示所有类别

List types = typeService.selectAll ();

model.addAttribute (“types”, types);

//添加博客页前展示所有标签

List tags = tagService.selectAll ();

model.addAttribute (“tags”, tags);

return “admin/blogs-input”;

@RequestMapping(“/add”)

public String add(Blog blog, @RequestParam(name = “tagIds”, required = false) List tagIds, RedirectAttributes attributes) {

blog.setViews (0);

blog.setCreateTime (new Date ());

blog.setUpdateTime (new Date ());

blog.setCommentCount (0);

blog.setTags (getTags (tagIds));

//获取用户id

UserInfo userInfo = (UserInfo) SecurityContextHolder.getContext ().getAuthentication ().getPrincipal ();

blog.setUserInfo (new UserInfo (userInfo.getId ()));

//封装完成,调用service层保存

Boolean save = blogService.save (blog);

if (save) {

attributes.addFlashAttribute (“message”, “添加成功!”);

} else {

attributes.addFlashAttribute (“message”, “添加失败!”);

return “redirect:showAll”;

public static List getTags(List tagIds) {

List tags = new ArrayList<> ();

for (Integer tagId : tagIds) {

tags.add (new Tag (tagId));

return tags;

@RequestMapping(“/toUpdate”)

public String toUpdate(Long id, Model model) {

Blog blog = blogService.selectById (id);

model.addAttribute (“blog”, blog);

List types = typeService.selectAll ();

model.addAttribute (“types”, types);

List tags = tagService.selectAll ();

model.addAttribute (“tags”, tags);

//用于展示标签

String tagIds = “”;

List tagList = blog.getTags ();

if (tagList.size () == 0 || tagList == null) {

tagIds = tagIds;

} else {

for (Tag tag : tagList) {

tagIds += “,” + tag.getId ();

tagIds = tagIds.substring (1);

model.addAttribute (“tagIds”, tagIds);

return “admin/blogs-update”;

@RequestMapping(“/update”)

public String update(Blog blog, @RequestParam(name = “tagIds”, required = false) List tagIds, RedirectAttributes attributes) {

blog.setUpdateTime (new Date ());

blog.setTags (getTags (tagIds));

//获取用户id

UserInfo userInfo = (UserInfo) SecurityContextHolder.getContext ().getAuthentication ().getPrincipal ();

blog.setUserInfo (new UserInfo (userInfo.getId ()));

Boolean update = blogService.update (blog);

if (update) {

attributes.addFlashAttribute (“message”, “修改成功!”);

} else {

attributes.addFlashAttribute (“message”, “修改失败!”);

return “redirect:showAll”;

@RequestMapping(“/deleteById”)

public String deleteById(Long id, RedirectAttributes attributes) {

Boolean aBoolean = blogService.deleteById (id);

if (aBoolean) {

attributes.addFlashAttribute (“message”, “删除成功!”);

} else {

attributes.addFlashAttribute (“message”, “删除失败!”);

return “redirect:showAll”;

登录用户管理控制层:

@Controller

@RequestMapping(“/front/comment”)

public class FrontCommentController {

@Autowired

private CommentService commentService;

@RequestMapping(“/addComment”)

public String addComment(Comment comment){

//获取登录的用户

UserInfo userInfo = (UserInfo) SecurityContextHolder.getContext ().getAuthentication ().getPrincipal ();

comment.setUserInfo (userInfo);

comment.setCreateTime (new Date ());

if (comment.getParentComment ().getId () == -1){

comment.getParentComment ().setId (null);

commentService.saveComment (comment);

return “redirect:showAllCommentByBlogId?id=”+comment.getBlog ().getId ();

@RequestMapping(“/showAllCommentByBlogId”)

public String showAllCommentByBlogId(@RequestParam(name = “pageNum”, required = false, defaultValue = “1”) Integer pageNum,

@RequestParam(name = “pageSize”, required = false, defaultValue = “6”) Integer pageSize,

@RequestParam(name = “id”) Long id, Model model){

List comments = commentService.selectByBlogIdAndParentCommentIsNull (pageNum, pageSize, id);

PageInfo pageInfo = new PageInfo<> (comments,8);

CommentServiceImpl commentServiceImpl = (CommentServiceImpl) commentService;

List commentList = commentServiceImpl.getAll (pageInfo.getList ()); //获取后代评论

pageInfo.setList (commentList); //封装好的顶级评论和后代评论设置给pageInfo的list

model.addAttribute (“pageInfo”,pageInfo);

return “blog :: commentList”;

博客信息管理控制层:

@Controller

@RequestMapping(“/front/message”)

public class FrontMessageController {

@Autowired

private MessageService messageService;

@RequestMapping(“/messages”)

public String messages(@RequestParam(name = “pageNum”, required = false, defaultValue = “1”) Integer pageNum,

@RequestParam(name = “pageSize”, required = false, defaultValue = “6”) Integer pageSize,

Model model) {

showAll (pageNum, pageSize, model);

return “messages”;

public void showAll(Integer pageNum, Integer pageSize, Model model){

List messages = messageService.selectAll (pageNum, pageSize);

PageInfo pageInfo = new PageInfo<> (messages, 8);

MessageServiceImpl messageServiceImpl = (MessageServiceImpl) messageService;

pageInfo.setList (messageServiceImpl.getAll (pageInfo.getList ()));

model.addAttribute (“pageInfo”, pageInfo);

@RequestMapping(“/addMessage”)

public String addMessage(Message message) {

UserInfo userInfo = (UserInfo) SecurityContextHolder.getContext ().getAuthentication ().getPrincipal ();

message.setUserInfo (userInfo);

message.setCreateTime (new Date ());

if (message.getParentMessage ().getId () == -1) {

message.getParentMessage ().setId (null);

messageService.saveMessage (message);

return “redirect:showAllMessages”;

@RequestMapping(“/showAllMessages”)

public String showAllMessages(@RequestParam(name = “pageNum”, required = false, defaultValue = “1”) Integer pageNum,

@RequestParam(name = “pageSize”, required = false, defaultValue = “6”) Integer pageSize,

Model model) {

showAll (pageNum, pageSize, model);

return “messages :: messageList”;


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值