package com.blog.controller;
import com.blog.pojo.Article;
import com.blog.pojo.Comment;
import com.blog.pojo.User;
import com.blog.service.RawNewsService;
import com.blog.service.impl.ArticleServiceImpl;
import com.blog.service.impl.CommentServiceImpl;
import com.blog.service.impl.LeaveMessageServiceImpl;
import com.blog.service.impl.UserServiceImpl;
import com.blog.utills.MyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.*;
import static com.blog.utills.MyUtils.contentHand;
import static com.blog.utills.MyUtils.formatTime;
@Controller
public class ArticleController {
@Autowired
private ArticleServiceImpl articleService;
@Autowired
private UserServiceImpl userService;
@Autowired
private LeaveMessageServiceImpl leaveMessageService;
@Autowired
private CommentServiceImpl commentService;
@Resource
private RawNewsService rawNewsService;
public ArticleServiceImpl getArticleService() {
return articleService;
}
/*
从编辑文章界面获取文章信息
*/
@RequestMapping("/admin/writeArticle")
public String writeArticle(String title,String author,String content,String tags,String type){
Article article = new Article(author,title,content,type,tags);
article.setPublishDate(formatTime(new Date()));
//将文章添加进入数据库
articleService.addArticle(article);
return "redirect:/admin/toEditorPage";
}
/*
首页文章分页渲染
page是前端异步请求传来的当前页数
*/
@RequestMapping("/{page}")
public String indexArticle(@PathVariable int page, Model model){
//查询网站首页的所有文章信息
List<Article> articles = articleService.queryAllArticle();
//文章总篇数
int articleSize = articles.size();
//一页最大显示数量
int pageSize = 3;
//最多分多少页
int maxPage = articleSize/pageSize;
if (articleSize%pageSize!=0) maxPage++;
if (page<=1) page = 1;
if (page>=maxPage) page = maxPage;
//当前查询开始的数值
int start = (page-1)*pageSize;
//查询到当前页面目标文章
List<Article> targetArticles = articleService.queryArticleByLimit(start, pageSize);
//当前页数传递给前端
int next = page+1;
int prev = page-1;
if (next>=maxPage) next = maxPage;
if (prev<=1) prev = 1;
model.addAttribute("next",next);
model.addAttribute("prev",prev);
//将当前页面的文章**处理后**传给前端
List<Article> contentHand = contentHand(targetArticles);
model.addAttribute("articles",contentHand);
System.out.println(page);
//查询所有的tag信息
List<Map<String, Object>> list = articleService.queryAllTags();
Set<String> set = new HashSet<>();
for (Map<String, Object> map : list) {
String[] tags = map.get("articleTags").toString().split(",");
for (String tag : tags) {
set.add(tag);
}
}
//标签云 字符串处理
String tags = set.toString();
tags = tags.substring(1,tags.length()-1);
tags = tags.replaceAll(" ","");
model.addAttribute("tags",tags);
//首页网站信息传递
model.addAttribute("articleSize",articleService.queryAllArticle().size());
model.addAttribute("tagSize",tags.split(",").length);
//最新留言传递
model.addAttribute("leaveMessages",leaveMessageService.queryAllLeaveMessageByLimit());
model.addAttribute("leaveMessageSize",leaveMessageService.queryAllLeaveMessage().size());
//将网站超级用户信息传给首页
User user = userService.queryAdminUser();
model.addAttribute("adminUser",user);
return "index";
}
/*
文章详情页面展示
*/
@GetMapping("/articlePage/{id}")
public String articlePage(@PathVariable int id,Model model){
//将这片文章信息传递过去
Article article = articleService.queryArticleById(id);
int articleId = id;
String Url = "";
int RawNewsId = articleService.getRawNewsIdById(articleId);
if (RawNewsId == 0){
Url = "http://localhost:8080/";
}
Url = rawNewsService.getUrlById(RawNewsId);
model.addAttribute("articleUrl",Url);
model.addAttribute("article",article);
//传递这篇文章所有的评论数
model.addAttribute("commentCount",commentService.querySumByArticle(id));
//传递这篇文章所有的顶级评论
List<Comment> topComments = commentService.queryAllCommentPid(id);
int size = topComments.size();
model.addAttribute("commentSize",size);
model.addAttribute("topComments",topComments);
//查询并处理所有的子评论
List<Map<Integer, Comment>> childComment = new ArrayList();//存放所有子评论的顶级评论id 和他的信息
Map<Integer,Comment> map = new HashMap();//存放子评论的最顶级的评论的id,和它的信息
List<Comment> childComments = commentService.queryAllComment(id);
int count = 0;//帮助计数
for (Comment comment : childComments) {
if (comment.getPid()!=0){//不是顶级评论
int i = MyUtils.queryTopCommentId(commentService, comment.getId(), comment.getPid());
Comment targetComment = commentService.queryCommentById(comment.getId());
targetComment.setPid(i);//设置当前的子评论id为最顶级的评论id 以便以传递前端判断
map.put(count,targetComment);
count++;
}
}
childComment.add(map);
model.addAttribute("childComment",childComment);
//传递头部头像信息
User user = userService.queryAdminUser();
model.addAttribute("topbar_imgUrl",user.getAvatarImgUrl());
return "articlePage";
}
/*
文章分类主页面
*/
@GetMapping("/articleTypePage/{type}/{page}")
public String articleTypePage(Model model,@PathVariable int page,@PathVariable String type){
//查询所有文章
List<Article> articles = articleService.queryAllArticle();
int allArticles = articles.size();
//一页6篇
int pageSize = 6;
//最多分多少页
int maxPage = allArticles/pageSize;
if (allArticles%pageSize!=0) maxPage++;
int start = (page-1)*pageSize;
//目标页数的文章信息
List<Article> targetArticles = articleService.queryArticleByLimit(start, pageSize);
model.addAttribute("articles",targetArticles);
//下一页上一页
int next = page+1;
int prev = page-1;
if (next>=maxPage) next = maxPage;
if (prev<=1) prev = 1;
model.addAttribute("next",next);
model.addAttribute("prev",prev);
//文章页面url区分****下一页上一页链接url是不同的
model.addAttribute("url","/articleTypePage/");
//查询文章分类信息
List<Map<String, String>> maps = articleService.queryArticleType();
model.addAttribute("maps",maps);
//传递头部头像信息
User user = userService.queryAdminUser();
model.addAttribute("topbar_imgUrl",user.getAvatarImgUrl());
return "articleType";
}
/*
文章分类界面的类型查询 及其分页
*/
//保存第一次传进来的类型
static String tempType = null;
@RequestMapping("/articleType/{type}/{page}")
public String articleType(@PathVariable String type,@PathVar
没有合适的资源?快使用搜索试试~ 我知道了~
大三期末设计基于java的新闻发布cms系统源码.zip
共169个文件
java:65个
html:45个
xml:12个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 132 浏览量
2022-11-27
15:57:21
上传
评论
收藏 1.68MB ZIP 举报
温馨提示
大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计基于java的新闻发布cms系统源码.zip 大三期末设计
资源推荐
资源详情
资源评论
收起资源包目录
大三期末设计基于java的新闻发布cms系统源码.zip (169个子文件)
$CACHE_FILE$ 2KB
amazeui.css 324KB
bootstrap.css 143KB
bootstrap.min.css 120KB
layui.css 73KB
bootstrap-datetimepicker.min.css 11KB
articlePage.css 5KB
jquery.bootgrid.min.css 4KB
articleType.css 2KB
index.css 2KB
header.css 167B
fontawesome-webfont.eot 75KB
glyphicons-halflings-regular.eot 20KB
.gitignore 259B
.gitignore 176B
articlePage.html 14KB
index.html 10KB
4xx.html 9KB
chatroom.html 8KB
leftbar.html 7KB
updateUserInfo.html 5KB
register.html 5KB
personInfo.html 5KB
articleType.html 4KB
tagcloud.html 4KB
allArticle.html 4KB
login.html 4KB
updateArticle.html 4KB
updateUserInfo.html 4KB
userList.html 4KB
forgetPwd.html 4KB
articleSearch.html 4KB
main.html 4KB
editor.html 4KB
addUser.html 3KB
commentList.html 3KB
leaveMessage.html 3KB
userListSearch.html 3KB
login.html 3KB
commentList.html 3KB
topbar.html 3KB
aboutMe.html 3KB
updateLeaveMessage.html 3KB
main.html 3KB
leaveMessageList.html 3KB
updatePwd.html 3KB
header.html 2KB
friendLinkList.html 2KB
friendLinkAdmin.html 2KB
updateFriendLink.html 2KB
updatePwd.html 2KB
newsSpider.html 2KB
topbar.html 2KB
friendLink.html 1KB
leftbar.html 761B
footer.html 749B
4xx - 副本.html 470B
failcode.html 210B
error.html 209B
fail.html 195B
favicon.ico 1KB
ArticleController.java 17KB
UserController.java 14KB
RootContorller.java 11KB
MyWebSocketHandler.java 5KB
NewsSpiderController.java 4KB
User.java 4KB
AuthImg.java 4KB
AuthImgController.java 4KB
ArticleServiceImpl.java 3KB
NewsSpiderServiceImpl.java 3KB
MyUtils.java 3KB
UserServiceImpl.java 2KB
CommentServiceImpl.java 2KB
CommentController.java 2KB
UserMapper.java 2KB
RawNewsServiceImpl.java 2KB
FriendLinkController.java 2KB
BlogApplicationTests.java 2KB
ChatController.java 2KB
LoginIntercepter.java 2KB
DruidConfig.java 2KB
UserInterceptor.java 2KB
ArticleMapper.java 2KB
CommentMapper.java 2KB
AdminInterceptor.java 2KB
Article.java 2KB
Login.java 2KB
HandShake.java 2KB
LeaveMessageServiceImpl.java 2KB
UserService.java 1KB
LeaveMessageController.java 1KB
BlogApplication.java 1KB
ArticleService.java 1KB
SimpleNews.java 1KB
News.java 1KB
CommentService.java 1KB
FriendServiceImpl.java 1KB
LoginServiceImpl.java 1KB
RawNewsMapper.java 1KB
共 169 条
- 1
- 2
资源评论
程序员张小妍
- 粉丝: 1w+
- 资源: 2604
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功