package web;
import dto.*;
import entity.Comment;
import entity.New;
import entity.User;
import enums.CommentEnums;
import enums.InsertNewEnums;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import service.CommentService;
import service.NewService;
import service.UserService;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;
/**
* @author yangxin
* @time 2018/12/27 14:58
*/
@Controller
@RequestMapping("/new")
public class NewController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private HttpSession session;
@Autowired
private NewService newService;
@Autowired
private CommentService commentService;
@Autowired
private UserService userService;
@RequestMapping(value = "/adminIndex.html")
public String adminIndex(Model model) {
User user = (User) session.getAttribute("user");
if (user != null) {//表示已经登录
List<NewsData> list = newService.selectAllNews();
model.addAttribute("Newslist", list);
return "AdminIndex";
}else{
return "redirect:/user/adminLogin.html";
}
}
@RequestMapping(value = "/commentlist.html")
public String commentlist(Model model){
User user = (User) session.getAttribute("user");
if (user != null) {//表示已经登录
List<CommentData> commentData = commentService.selectAllComment();
model.addAttribute("commentlist", commentData);
return "AdminIndexComment";
}else{
return "redirect:/user/adminLogin.html";
}
}
@RequestMapping(value = "/userlist.html")
public String userlist(Model model){
User user = (User) session.getAttribute("user");
if (user != null) {//表示已经登录
List<User> list = userService.selectAllUser();
model.addAttribute("userList", list);
return "AdminIndexUser";
}else{
return "redirect:/user/adminLogin.html";
}
}
@RequestMapping(value = "deletecomment")
public String deleteComment(long commentId, String userName, Model model) {
// logger.info("############yangxin专用日志########### XX功能模块的XX数据:"+);
User user = userService.selectByName(userName);
User login= (User) session.getAttribute("user");
Comment comment = commentService.selectCommentById(commentId);
if (login.getUserType() == 2 || user.getUserId() == login.getUserId()) {
int i = commentService.deleteComment(commentId, user.getUserId());
if (i <= 0) {
NewsResult<Comment> result = new NewsResult<Comment>(false, CommentEnums.FAIL.getStateInfo());
model.addAttribute("editResult", result);
} else {
//如果不是作者本人或者是管理员那么不允许修改文章。
NewsResult<Comment> result = new NewsResult<Comment>(true, CommentEnums.SUCCESS.getStateInfo());
model.addAttribute("editResult", result);
}
} else {
//如果不是作者本人或者是管理员那么不允许修改文章。
NewsResult<Comment> result = new NewsResult<Comment>(false, CommentEnums.UNOPERATION.getStateInfo());
model.addAttribute("editResult", result);
}
if (login.getUserType() == 2)
return "redirect:/new/commentlist.html";
else
return "redirect:/user/index.html";
}
@RequestMapping("/submitcomment")
public String submitComment(String commentContent, long newId, Model model) {
logger.info("*************提交评论获取内容:" + commentContent + newId);
User user = (User) session.getAttribute("user");
logger.info("**************目前是否登录:" + user);
if (user != null) {//目前已经登录
Comment comment = new Comment();
comment.setContent(commentContent);
comment.setNewId(newId);
comment.setUserId(user.getUserId());
comment.setCreateTime(new Date());
CommentState commentState = commentService.insertComment(comment);
if (commentState.getState()!=1) {//插入失败
NewsResult<Comment> result = new NewsResult<Comment>(false, CommentEnums.INTERBUSY.getStateInfo());
model.addAttribute("insertComment", result);
} else {
NewsResult<Comment> result = new NewsResult<Comment>(true, CommentEnums.SUCCESS.getStateInfo());
model.addAttribute("insertComment", result);
}
} else {//表示未登录
NewsResult<Comment> result = new NewsResult<Comment>(false, CommentEnums.UNLOGIN.getStateInfo());
model.addAttribute("insertComment", result);
return "redirect:/user/login1.html";
}
return "redirect:/new/detail?newId=" + newId;
}
@RequestMapping(value = "/editor.html")
public String editor(int index) {
User user = (User) session.getAttribute("user");
if (user != null) {//表示已经登录
return "editor";
}else{
if(index==1)
return "redirect:/user/login1.html";
return "redirect:/user/adminLogin.html";
}
}
@RequestMapping("/detail")
public String detail(long newId, Model model) {
NewDetail newsData = newService.selectNew(newId);
List<CommentData> list = commentService.selectCommentByNew(newId);
logger.info("************新闻详细信息的新闻数据***************" + newsData.getUser());
logger.info("************新闻详细信息的评论数据***************" + list);
model.addAttribute("detaildata", newsData);
model.addAttribute("commentlist", list);
return "newsdetail";
}
@RequestMapping(value = "/submitContent")
public String toSubmit(New news, Model model) {
User user = (User) session.getAttribute("user");
if (user != null) {
news.setUserId(user.getUserId());
//先确定有没有这个片文章再插入。
New aNew = newService.selectNewsBytitle(news.getTitle());
if(aNew!=null){//表示已经存在
NewsResult<New> result = new NewsResult<New>(false, InsertNewEnums.EXIST.getStateinfo());
model.addAttribute("insertNewResult", result);
return "editor";
}else{
InsertNewState state = newService.insertNew(news);
if (state.getState() != 1) {//表示失败
NewsResult<New> result = new NewsResult<New>(false, state.getStateInfo());
model.addAttribute("insertNewResult", result);
return "editor";
} else {
NewsResult<New> result = new NewsResult<New>(true, news);
model.addAttribute("insertNewResult", result);
if(user.getUserType()==2)
return "redirect:/new/adminIndex.html";
return "redirect:/user/index.html";
}
}
} else {
NewsResult<New> result = new NewsResult<New>(false, InsertNewEnums.UNLOGIN.getStateinfo());
model.addAttribute("insertNewResult", result);
return "editor";
}
}
@RequestMapping(value = "/delete")
public String delete(long newId, String userName,int tag, Model model) {
logger.info("****************" + newId + "," + userName);
User user = userService.selectByName(userName);
InsertNewState state = ne
没有合适的资源?快使用搜索试试~ 我知道了~
基于SSM框架的新闻发布系统 .zip
共1133个文件
png:443个
js:190个
jpg:117个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 70 浏览量
2023-11-12
10:58:26
上传
评论
收藏 116.31MB ZIP 举报
温馨提示
1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 -------- 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。
资源推荐
资源详情
资源评论
收起资源包目录
基于SSM框架的新闻发布系统 .zip (1133个子文件)
.classpath 4KB
bootstrap.css 118KB
bootstrap.css 118KB
style.css 60KB
style.css 60KB
style2.css 44KB
style2.css 44KB
ueditor.css 43KB
ueditor.css 43KB
ueditor.min.css 34KB
ueditor.min.css 34KB
video-js.css 21KB
video-js.css 21KB
image.css 18KB
image.css 18KB
video.css 15KB
video.css 15KB
attachment.css 14KB
attachment.css 14KB
summernote.css 14KB
summernote.css 14KB
video-js.min.css 11KB
video-js.min.css 11KB
style-responsive.css 10KB
style-responsive.css 10KB
owl.carousel.css 8KB
owl.carousel.css 8KB
shCoreDefault.css 7KB
shCoreDefault.css 7KB
daterangepicker-bs3.css 5KB
daterangepicker-bs3.css 5KB
daterangepicker.css 4KB
daterangepicker.css 4KB
scrawl.css 4KB
scrawl.css 4KB
zabuto_calendar.css 4KB
zabuto_calendar.css 4KB
index.css 3KB
index.css 3KB
table-responsive.css 3KB
table-responsive.css 3KB
codemirror.css 3KB
codemirror.css 3KB
charts.css 3KB
charts.css 3KB
background.css 2KB
background.css 2KB
bootstrap-wysihtml5.css 2KB
bootstrap-wysihtml5.css 2KB
emotion.css 2KB
emotion.css 2KB
to-do.css 2KB
to-do.css 2KB
dialogbase.css 2KB
dialogbase.css 2KB
music.css 2KB
music.css 2KB
edittable.css 1KB
edittable.css 1KB
template.css 1KB
template.css 1KB
webuploader.css 515B
webuploader.css 515B
help.css 389B
help.css 389B
iframe.css 350B
iframe.css 350B
org.news.eml 3KB
YxNews.eml 3KB
vjs.eot 3KB
vjs.eot 3KB
UEditorSnapscreen.exe 508KB
UEditorSnapscreen.exe 508KB
wface.gif 49KB
wface.gif 49KB
jxface2.gif 40KB
jxface2.gif 40KB
yface.gif 28KB
yface.gif 28KB
bface.gif 27KB
bface.gif 27KB
icons.gif 20KB
icons.gif 20KB
file-icons.gif 20KB
file-icons.gif 20KB
file-icons.gif 20KB
file-icons.gif 20KB
tface.gif 19KB
tface.gif 19KB
fface.gif 18KB
fface.gif 18KB
cface.gif 8KB
cface.gif 8KB
icons-all.gif 4KB
icons-all.gif 4KB
videologo.gif 2KB
videologo.gif 2KB
cancelbutton.gif 1KB
cancelbutton.gif 1KB
button-bg.gif 1KB
共 1133 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
资源评论
程皮
- 粉丝: 279
- 资源: 2566
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功