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

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

050023502402

060023502402

070023502402

080023502402

090023502402

100023502402

110023502402

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

项目介绍

本系统是一个个人博客的管理系统,用户可以注册账号并登陆系统查看发布的文章并进行阅读评论等 本系统主要有三种用户: 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@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<Type> types = typeService.selectAll ();
mv.addObject ("types", types);

//调用业务层方法
List<Blog> blogs = blogService.selectAll (pageNum, pageSize, title, typeId, recommend);
PageInfo<Blog> 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) {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
        PageInfo<Message> pageInfo = new PageInfo<> (messages, 8);
model.addAttribute ("pageInfo", pageInfo);

}

@RequestMapping("/showAll/search")
public String search(@RequestParam(name = "pageNum", required = false, defaultValue = "1") Integer pageNum,
@RequestParam(name = "pageSize", required = false, defaultValue = "6") Integer pageSize,
@RequestParam(name = "content", required = false, defaultValue = "") String content,
@RequestParam(name = "email", required = false, defaultValue = "") String email,
Model model) {

show (pageNum, pageSize, content, email, model);

return "admin/messages :: messageList";
}

@RequestMapping("/deleteById")
public String deleteById(Integer id, RedirectAttributes attributes){

try {
messageService.deleteById(id);
attributes.addFlashAttribute ("message","删除成功!");
} catch (Exception e) {
attributes.addFlashAttribute ("message","删除失败,服务器异常!");
e.printStackTrace ();
}

return "redirect:showAll";
}
}
package com.zp.blog.web.back;



@Controller
@RequestMapping("/admin/syslog")
public class AdminSysLogController {

@Autowired
private SysLogService sysLogService;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
                          @RequestParam(name = "pageSize", required = false, defaultValue = "2") Integer pageSize,
@RequestParam(name = "email", required = false, defaultValue = "") String email, Model model) {

show (pageNum, pageSize, email, model);
return "admin/users";
}

public void show(Integer pageNum, Integer pageSize, String email, Model model){
List<UserInfo> userInfos = userService.selectAll (pageNum, pageSize, email);
PageInfo<UserInfo> pageInfo = new PageInfo<> (userInfos,8);
model.addAttribute ("pageInfo",pageInfo);
model.addAttribute ("email",email);
}

@RequestMapping("/showAll/search")
public String search(@RequestParam(name = "pageNum", required = false, defaultValue = "1") Integer pageNum,
@RequestParam(name = "pageSize", required = false, defaultValue = "2") Integer pageSize,
@RequestParam(name = "email", required = false, defaultValue = "") String email, Model model) {

show (pageNum, pageSize, email, model);
return "admin/users :: userList";
}

@RequestMapping("/updateStatus")
public String updateStatus(String email, RedirectAttributes attributes) {
UserInfo userInfo = userService.findByEmail (email);
Boolean status = userInfo.getStatus ();

try {
userService.updateStatus (email, !status);
attributes.addFlashAttribute ("message","状态修改成功!");
} catch (Exception e) {
attributes.addFlashAttribute ("message","状态修改失败,服务器异常!");
e.printStackTrace ();
}


return "redirect:showAll";
}



}
package com.zp.blog.security;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    List<Blog> blogs = blogService.selectAll (pageNum, pageSize, title, typeId, recommend);
PageInfo<Blog> pageInfo = new PageInfo<> (blogs, 5);

model.addAttribute ("pageInfo", pageInfo);
return "admin/blogs::blogList";
}

@RequestMapping("/toAdd")
public String toAdd(Model model) {

//添加博客页前展示所有类别
List<Type> types = typeService.selectAll ();
model.addAttribute ("types", types);

//添加博客页前展示所有标签
List<Tag> tags = tagService.selectAll ();
model.addAttribute ("tags", tags);

return "admin/blogs-input";
}

@RequestMapping("/add")
public String add(Blog blog, @RequestParam(name = "tagIds", required = false) List<Integer> 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<Tag> getTags(List<Integer> tagIds) {
List<Tag> tags = new ArrayList<> ();
for (Integer tagId : tagIds) {
tags.add (new Tag (tagId));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
    if (type1 != null){
result.rejectValue ("name","nameError","不能添加重复的类别名称");
}

if (result.hasErrors ()){
return "admin/types-input";
}

//调用service层保存类别
Boolean save = typeService.save (type);

if (save){
attributes.addFlashAttribute ("message","添加成功!");
} else {
attributes.addFlashAttribute ("message","添加失败!");
}

return "redirect:showAll";
}


@RequestMapping("/toUpdate")
public ModelAndView toUpdate(Integer id){
ModelAndView mv = new ModelAndView ();

Type type = typeService.selectById (id);

mv.addObject ("type",type);
mv.setViewName ("admin/types-update");
return mv;
}

@RequestMapping("/update")
public String update(@Valid Type type, BindingResult result, RedirectAttributes attributes){

Type type1 = typeService.selectByName (type.getName ());
if (type1 != null){
result.rejectValue ("name","nameError","该类别名称已存在,不能修改!");
}

if (result.hasErrors ()){
return "admin/types-update";
}

Boolean update = typeService.update (type);
if (update){
attributes.addFlashAttribute ("message","修改成功!");
} else {
attributes.addFlashAttribute ("message","修改失败!");
}

return "redirect:showAll";


项目链接:
https://javayms.github.io?id=411122512008200my
https://javayms.pages.dev?id=411122512008200my