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

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

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

适用

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

功能说明

370023292402

380023292402

390023292402

400023292402

420023292402

430023292402

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

一、项目简述

项目内容包括:首页,登陆,新建文章,搜索,登陆日志,登录次数,评论统计,相关信息,文章列表等其他相关功能

另外:系统采用MVC架构思想

二、项目运行

1.运行环境 jdk8+tomcat8+mysql+Eclispe( IntelliJ IDEA , MyEclispe ,Sts 都支持,代码与开发环境运行无关啦,只需要调整环境即可)

SpringMVC+Spring+Mybatis+JavaWeb+MySQL+Servlert+Ajax+HTML+JavaScript+CSS+Jsp等等。

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


@Controller
public class LoginController {
@Autowired
AdminServiceImpl adminService;
@Autowired
AdminLoginLogServiceImpl adminLoginLogService;
@RequestMapping(value = {"/admin/index","/admin","/admin/login"})
public String toIndex(HttpServletRequest request) {

return "admin/login";


}

// 0:用户不存在 1:密码错误 2:登陆成功
@RequestMapping(value = "/api/loginCheck", method = RequestMethod.POST)
public @ResponseBody Object loginCheck(HttpServletRequest request,HttpServletResponse httpServletResponse) {
int id=Integer.parseInt(request.getParameter("id"));
String passwd = request.getParameter("password");
HashMap<String, String> res = new HashMap<String, String>();
if(adminService.getById(id)==null){
res.put("stateCode", "0");
}
else if(!adminService.getById(id).getPassword().equals(passwd)){
res.put("stateCode", "1");
}else {
String ip=request.getRemoteAddr();
AdminLoginLog adminLoginLog=new AdminLoginLog();
adminLoginLog.setAdminId(id);
adminLoginLog.setDate(new Date());
adminLoginLog.setIp(ip);
int log=adminLoginLogService.insert(adminLoginLog);
Cookie cookie = new Cookie("userId",""+id);
cookie.setMaxAge(3600*24);
httpServletResponse.addCookie(cookie);
request.getSession().setAttribute("admin",adminService.getById(id));
res.put("stateCode", "2");
}
return res;
}

@RequestMapping(value = {"/admin/logout"})
public String logout(HttpServletRequest request,HttpServletResponse response) {
request.getSession().removeAttribute("admin");
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



@Controller
public class ArticleController {
@Autowired
ArticleServiceImpl articleService;
@Autowired
public CommentServiceImpl commentService;
@RequestMapping("/article")
public ModelAndView detail(HttpServletRequest request){
int id=Integer.parseInt(request.getParameter("id"));
List<Comment> comments=commentService.allComments(id,0,10);
Article article=articleService.selectById(id);
Article lastArticle=articleService.selectLastArticle(id);
Article nextArticle=articleService.selectNextArticle(id);
Integer clickNum=article.getClick();
article.setClick(clickNum+1);
articleService.updateArticle(article);
ModelAndView modelAndView=new ModelAndView("detail");
modelAndView.addObject("article",article);
modelAndView.addObject("comments",comments);
modelAndView.addObject("lastArticle",lastArticle);
modelAndView.addObject("nextArticle",nextArticle);
return modelAndView;
}
@RequestMapping("/admin/article/detail")
public ModelAndView adminArticleDetail(HttpServletRequest request){
int id=Integer.parseInt(request.getParameter("id"));
Article article=articleService.selectById(id);
ModelAndView modelAndView=new ModelAndView("/admin/article_detail");
modelAndView.addObject("article",article);
return modelAndView;
}
@RequestMapping("/admin/article/comment")
public ModelAndView adminArticleComment(HttpServletRequest request){
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
        if(commentService.insertComment(comment)>0){
res.put("stateCode", "1");
}else {
res.put("stateCode", "0");
}
return res;
}
@RequestMapping(value = "/api/comment/del", method = RequestMethod.POST)
public @ResponseBody Object commentDel(HttpServletRequest request) {
long id=Long.parseLong(request.getParameter("id"));
HashMap<String, String> res = new HashMap<String, String>();
if (commentService.delById(id)){
res.put("stateCode", "1");
}else {
res.put("stateCode", "0");
}
return res;
}
}
package com.blog.web;



@Controller
public class IndexController {
@Autowired
public ArticleServiceImpl articleService;
@Autowired
public CommentServiceImpl commentService;
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
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String word=request.getParameter("word");
List<Article> articles=articleService.selectByWord(word);
ModelAndView modelAndView=new ModelAndView("/admin/article_list");
modelAndView.addObject("articles",articles);
return modelAndView;
}
@RequestMapping(value = "/admin/article/edit")
public ModelAndView articleEdit(HttpServletRequest request){
int id=Integer.parseInt(request.getParameter("id"));
Article article=articleService.selectById(id);
ModelAndView modelAndView=new ModelAndView("/admin/article_edit");
modelAndView.addObject("article",article);
return modelAndView;
}
@RequestMapping(value = "/admin/article/edit/do")
public ModelAndView articleEditDo(HttpServletRequest request){
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Article article=new Article();
article.setId(Integer.parseInt(request.getParameter("id")));
article.setTitle(request.getParameter("title"));
article.setCatalogId(Integer.parseInt(request.getParameter("catalogId")));
article.setKeywords(request.getParameter("keywords"));
article.setdesci(request.getParameter("desci"));
article.setContent(request.getParameter("content"));
ModelAndView modelAndView=new ModelAndView("/admin/article_edit");
if (articleService.updateArticle(article)){
modelAndView.addObject("succ", "修改文章成功!");

}else {
modelAndView.addObject("error", "修改文章失败!");
}
return modelAndView;
}
@RequestMapping(value = "/api/article/del", method = RequestMethod.POST)
public @ResponseBody Object loginCheck(HttpServletRequest request) {
int id=Integer.parseInt(request.getParameter("id"));
int result=articleService.deleteById(id);
HashMap<String, String> res = new HashMap<String, String>();
if (result==1){
res.put("stateCode", "1");
}else {
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
      article.setKeywords(request.getParameter("keywords"));
article.setdesci(request.getParameter("desci"));
article.setContent(request.getParameter("content"));
article.setTime(new Date());
if (articleService.insert(article)){
redirectAttributes.addFlashAttribute("succ", "发表文章成功!");
return "redirect:/admin/article/add";
}else {
redirectAttributes.addFlashAttribute("error", "发表文章失败!");
return "redirect:/admin/article/add";
}
}
@RequestMapping(value = "/admin/article/search")
public ModelAndView articleSearch(HttpServletRequest request){
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String word=request.getParameter("word");
List<Article> articles=articleService.selectByWord(word);
ModelAndView modelAndView=new ModelAndView("/admin/article_list");
modelAndView.addObject("articles",articles);
return modelAndView;
}
@RequestMapping(value = "/admin/article/edit")
public ModelAndView articleEdit(HttpServletRequest request){
int id=Integer.parseInt(request.getParameter("id"));
Article article=articleService.selectById(id);
ModelAndView modelAndView=new ModelAndView("/admin/article_edit");
modelAndView.addObject("article",article);
return modelAndView;
}
@RequestMapping(value = "/admin/article/edit/do")
public ModelAndView articleEditDo(HttpServletRequest request){
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Article article=new Article();
article.setId(Integer.parseInt(request.getParameter("id")));
article.setTitle(request.getParameter("title"));
article.setCatalogId(Integer.parseInt(request.getParameter("catalogId")));
article.setKeywords(request.getParameter("keywords"));
article.setdesci(request.getParameter("desci"));
article.setContent(request.getParameter("content"));


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