package com.blog.web;
import com.blog.domain.Article;
import com.blog.domain.Comment;
import com.blog.service.impl.ArticleServiceImpl;
import com.blog.service.impl.CommentServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@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){
int id=Integer.parseInt(request.getParameter("id"));
List<Comment> comments=commentService.allComments(id,0,10);
ModelAndView modelAndView=new ModelAndView("/admin/comment_list");
modelAndView.addObject("comments",comments);
return modelAndView;
}
@RequestMapping("/admin/article/list")
public ModelAndView articleList(@RequestParam(required=true,defaultValue="1") Integer page, @RequestParam(required=false,defaultValue="10") Integer pageSize){
PageHelper.startPage(page, pageSize);
List<Article> articles=articleService.queryAll();
PageInfo<Article> pageInfo=new PageInfo<Article>(articles);
ModelAndView modelAndView=new ModelAndView("/admin/article_list");
modelAndView.addObject("articles",articles);
modelAndView.addObject("pageInfo",pageInfo);
return modelAndView;
}
@RequestMapping("/admin/article/add")
public ModelAndView articleAdd(){
ModelAndView modelAndView=new ModelAndView("/admin/article_add");
return modelAndView;
}
@RequestMapping("/admin/article/add/do")
public String articleAddDo(HttpServletRequest request,RedirectAttributes redirectAttributes){
Article article=new Article();
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"));
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){
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){
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 {
res.put("stateCode", "0");
}
return res;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
博客管理系统SSM.zip (79个子文件)
Blog-System-master
blog.sql 91KB
pom.xml 7KB
src
main
resources
mapper
AdminLoginLogMapper.xml 3KB
ArticleMapper.xml 6KB
AdminMapper.xml 2KB
CommentMapper.xml 4KB
CatalogMapper.xml 4KB
logback.xml 436B
spring
spring-web.xml 2KB
spring-dao.xml 3KB
spring-service.xml 780B
jdbc.properties 125B
mybatis-config.xml 993B
log4j.properties 981B
java
com
blog
web
WebConfig.java 2KB
IndexController.java 1KB
AdminController.java 3KB
LoginController.java 3KB
CommentController.java 2KB
ArticleController.java 6KB
dao
AdminLoginLogDao.java 614B
AdminDao.java 394B
CatalogDao.java 462B
CommentDao.java 701B
ArticleDao.java 720B
service
ArticleService.java 517B
AdminService.java 123B
AdminLoginLogService.java 279B
impl
ArticleServiceImpl.java 1KB
AdminLoginLogServiceImpl.java 795B
AdminServiceImpl.java 445B
CommentServiceImpl.java 811B
CommentService.java 284B
domain
Comment.java 1KB
Admin.java 626B
AdminLoginLog.java 945B
Article.java 2KB
Catalog.java 948B
webapp
WEB-INF
lib
commons-io-2.4.jar 181KB
json.jar 45KB
ueditor-1.1.2.jar 30KB
commons-codec-1.9.jar 258KB
commons-fileupload-1.3.1.jar 67KB
web.xml 2KB
rest-servlet.xml 755B
blog-servlet.xml 1KB
jsp
index.jsp 8KB
detail.jsp 13KB
admin
article_detail.jsp 1KB
article_edit.jsp 3KB
article_add.jsp 3KB
comment_list.jsp 3KB
article_list.jsp 6KB
main.jsp 4KB
login.jsp 10KB
about.jsp 7KB
static
js
jquery.slim.min.js 68KB
wangEditor.min.js 66KB
bootstrap.min.js 36KB
popper.min.js 19KB
layer.js 19KB
jquery-3.2.1.min.js 85KB
skin
default
loading-2.gif 2KB
loading-1.gif 701B
loading-0.gif 6KB
icon-ext.png 6KB
icon.png 11KB
layer.css 14KB
bootstrap4.0.min.js 50KB
css
bootstrap.min.css 118KB
article.css 3KB
bootstrap4.0.min.css 122KB
about.css 3KB
images
82839-106.jpg 436KB
web-icon.png 202KB
296494-106.jpg 239KB
bg.png 6KB
me.jpg 194KB
105905-106.jpg 333KB
共 79 条
- 1
资源评论
专治八阿哥的孟老师
- 粉丝: 2496
- 资源: 114
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 筷手引流工具.apk
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功