基于javaweb的SSM+Maven个人博客管理系统(java+ssm+js+jsp+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

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

适用

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

功能说明

520023142402

530023142402

540023142402

550023142402

560023142402

570023142402

基于javaweb的SSM+Maven个人博客管理系统(java+ssm+js+jsp+mysql)

项目介绍

管理员角色包含以下功能: 发表文章,查看文章,类别管理,添加类别,个人信息管理,评论管理,评论审核等功能。

用户角色包含以下功能: 首页,博客详情,文章分类,评论等功能。

环境需要

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版本;

技术栈

  1. 后端:Spring+SpringMVC+Mybatis 2. 前端:HTML+CSS+JavaScript+jsp

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application.yml配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/ 登录

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
			pageBean, param.toString());
model.addAttribute("pageCode", pageCode);
model.addAttribute("entry", map);
model.addAttribute("blogList", blogService.getBlogList(map));
return "blog/list";
}

@RequestMapping("/toAdd")
public String toAdd(Model model) {
model.addAttribute("blogTypeList", blogTypeService.getTypeList());
return "blog/add";
}

@RequestMapping("/toUpdate")
public String toUpdate(Integer id, Model model) {
model.addAttribute("blogTypeList", blogTypeService.getTypeList());
Blog blog = blogService.findById(id);
model.addAttribute("blog", blog);
BlogType blogType = blog.getBlogType();
if(blogType != null){
model.addAttribute("typeId", blogType.getTypeId());
}
return "blog/update";
}

@RequestMapping("/add")
public void add(Blog blog, @RequestParam(value = "img") MultipartFile file,
Model model) throws Exception {

// 获取原始文件名
String fileName = file.getOriginalFilename();
int index = fileName.indexOf(".");
String imageUrl = null;
String imagePath = DateUtils.getTimeStrForImage();
if (index != -1) {
//生成新文件名
imageUrl = imagePath + fileName.substring(index);
log.info("add {}", imagePath);
handleFileUpload(file, imageUrl);
blog.setImage(imageUrl);
}
// 添加博客及索引
int result = blogService.add(blog);
model.addAttribute("msg", result > 0 ? "保存成功" : "保存失败");
}

@RequestMapping("/update")
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


/**
* 主页Controller
*/
@Controller
public class IndexController {

@Resource
private BlogService blogService;

@Resource
private BloggerService bloggerService;

@Resource
private BlogTypeService blogTypeService;

@Resource
private LinkService linkService;

@Resource
private BlogIndex blogIndex;

@RequestMapping("/index")
public String index(@RequestParam(defaultValue = "1") Integer page,
Model model, HttpServletRequest request) throws Exception {
Map<String, Object> map = new HashMap<String, Object>(2);
int totalCount = blogService.getCount(map);
int pageSize = Constants.FRONT_PAGE_SIZE;
PageBean pageBean = new PageBean(totalCount, page, pageSize);
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

@Controller
@RequestMapping("/comment")
public class CommentController {

@Resource
private UserMapper userMapper;

@Resource
private CommentService commentService;

/**
* 用户评论
* @param comment
* @param user
* @param response
*/
@RequestMapping("/save")
public void save(String vCode, Integer blogId, Comment comment, User user,
HttpServletResponse response, HttpSession session) {
String validateCode = (String) session.getAttribute(Constants.VALIDATE_CODE);
JSONObject jsonObj = new JSONObject();
if (StringUtils.isEmpty(validateCode) || !validateCode.equalsIgnoreCase(vCode)) {
jsonObj.put("success", false);
jsonObj.put("errorInfo", "验证码错误");
ResponseUtils.writeJson(response, jsonObj.toString());
return;
}
int result = 0;
Integer userId = user.getId();
if (userId == null) {
userId = userMapper.insertSelective(user);
}
comment.setBlogId(blogId);
comment.setUserId(userId);
comment.setUserName(user.getUserName());
comment.setContent(StringEscapeUtils.escapeHtml4(comment.getContent()));
result = commentService.add(comment);
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
			typeName = Constants.NEWS_CATEGORY; break;
default: break;
}
Integer typeId = blogTypeService.getIdByName(typeName);
Map<String, Object> map = new HashMap<String, Object>(3);
map.put("typeId", typeId);
int totalCount = blogService.getCount(map);
int pageSize = Constants.FRONT_PAGE_SIZE;
PageBean pageBean = new PageBean(totalCount, page, pageSize);
pageBean.setTotalCount(totalCount);
map.put("start", pageBean.getStart());
map.put("size", pageSize);

List<Blog> blogList = blogService.getBlogList(map);
// 去除摘要中的html标签,防止浏览器解析
blogList.forEach(blog -> blog.setSummary(StringUtils.escapeHtml(blog.getSummary())));
model.addAttribute("blogList", blogList);
String pageCode = PageUtils.genPagination(request.getContextPath() + "/" + category + ".shtml",
pageBean, "");
model.addAttribute("pageCode", pageCode);
model.addAttribute("totalCount", totalCount);
model.addAttribute("pageTitle", typeName + " - 文章分类 - hayuq的博客");
model.addAttribute("title", typeName);
return "blog/list";
}

/**
* 根据关键词查询博客
* @throws Exception
*/
@RequestMapping("/search")
public String search(@RequestParam(defaultValue = "1") Integer page, String q,
Model model, HttpServletRequest request) throws Exception {
if ("POST".equals(request.getMethod())) { // 判断是否是表单提交,post方式
// 解决表单提交中文乱码
q = new String(q);
}
if(q != null) {
// URL解码,防止特殊字符
q = URLDecoder.decode(q, StandardCharsets.UTF_8.name());
}
// 转义特殊字符,防止lucene报异常
String kwd = QueryParser.escape(q);
List<Blog> blogList = blogIndex.query(kwd);
// 分页显示
int totalCount = blogList.size();
int pageSize = Constants.DEFAULT_PAGE_SIZE;
PageBean pageBean = new PageBean(totalCount, page, pageSize);
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
public String toModifyInfo(Model model) {
model.addAttribute("blogger", bloggerService.find());
return "blogger/modifyInfo";
}

@RequestMapping("/toModifyPassword")
public String toModifyPassword() {
return "blogger/modifyPassword";
}

@RequestMapping("/modifyInfo")
public void modifyInfo(Blogger blogger,
@RequestParam(value = "img", required = false) MultipartFile file,
Model model) throws Exception {

if (file != null) { //上传图片
// 获取原始文件名
String fileName = file.getOriginalFilename();
int index = fileName.indexOf(".");
String imageUrl = null;
if (index != -1) {
// 生成新文件名
imageUrl = DateUtils.getTimeStrForImage() + fileName.substring(index);
handleFileUpload(file, imageUrl);
blogger.setImageUrl(imageUrl);
}
}
int result = bloggerService.update(blogger);
model.addAttribute("msg", result > 0 ? "保存成功" : "保存失败");
}

@RequestMapping("/modifyPassword")
public void modifyPassword(String newpwd, String oldpwd, String repwd, HttpServletResponse response,
HttpServletRequest request) {

Blogger blogger = bloggerService.find();
if (!blogger.getPassword().equals(ShiroUtils.encryptPassword(oldpwd))) {
ResponseUtils.writeText(response, "原密码输入不正确");
return;
}
if (!newpwd.equals(repwd)) {
ResponseUtils.writeText(response, "两次密码输入不一致");
return;
}
blogger.setPassword(ShiroUtils.encryptPassword(newpwd));
bloggerService.update(blogger);
ResponseUtils.writeText(response, "修改成功");
}

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
53
		Model model) throws Exception {

// 获取原始文件名
String fileName = file.getOriginalFilename();
int index = fileName.indexOf(".");
String imageUrl = null;
String imagePath = DateUtils.getTimeStrForImage();
if (index != -1) {
//生成新文件名
imageUrl = imagePath + fileName.substring(index);
log.info("add {}", imagePath);
handleFileUpload(file, imageUrl);
blog.setImage(imageUrl);
}
// 添加博客及索引
int result = blogService.add(blog);
model.addAttribute("msg", result > 0 ? "保存成功" : "保存失败");
}

@RequestMapping("/update")
public void update(Blog blog, @RequestParam(value = "img", required=false) MultipartFile file,
Model model) throws Exception {

if (file != null) { //上传图片
// 获取原始文件名
String fileName = file.getOriginalFilename();
int index = fileName.indexOf(".");
String imageUrl = null;
String imagePath = DateUtils.getTimeStrForImage();
if(index != -1){
//生成新文件名
imageUrl = imagePath + fileName.substring(index);
log.info("update {}", imagePath);
handleFileUpload(file,imageUrl);
blog.setImage(imageUrl);
}
}
//更新博客及索引
int result = blogService.update(blog);
model.addAttribute("msg", result > 0 ? "保存成功" : "保存失败");
}

@RequestMapping("/delete")
public String delete(Integer id) throws IOException {
// 删除博客、索引及评论
blogService.delete(id);
return "redirect:/blog/list.do";
}

@RequestMapping("/deletes")
public String deletes(String ids) throws IOException {
String[] idArr = org.springframework.util.StringUtils.commaDelimitedListToStringArray(ids);
int len = idArr.length;


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