/**
*
*/
package com.phn.action;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.phn.bean.Comments;
import com.phn.bean.News;
import com.phn.bean.Pages;
import com.phn.bean.Topics;
import com.phn.bean.Types;
import com.phn.bean.Users;
import com.phn.service.TopicService;
/**
* @author 潘海南
* @email phnlove@163.com
*/
public class TopicAction {
private TopicService topicService;
private Topics topic;
private Types ttype;
private News tnew;
private Pages pageBean;
private int nowPage = 1;
private int listFloor[];
private int comFlag = 0;
private String content;
private List<Topics> listTopic;
private List<Comments> listComment;
HttpSession session = ServletActionContext.getRequest().getSession();
HttpServletResponse response = ServletActionContext.getResponse();
HttpServletRequest request = ServletActionContext.getRequest();
public String add() throws Exception {
Users user = (Users) session.getAttribute("tu");
boolean flag = this.topicService.add(topic, user, response, request,
ttype);
if (flag != true) {
return "topic_add_no";
}
return "topic_add_ok";
}
/**
* 去往指定的帖子,默认只显示未被删除的评论
*
* @return
* @throws Exception
*/
public String goTopic() throws Exception {
Topics top = this.topicService.find(topic.getId());
if(top == null){
return "error";
}
List<Comments> list = new ArrayList<Comments>();
List<Comments> listTemp = new ArrayList<Comments>();
listTemp.addAll(top.getTopicComments());
if (this.comFlag == 0) {
for (int i = 0; i < listTemp.size(); i++) {
if (listTemp.get(i).getStatus() == 0) {
list.add(listTemp.get(i));
}
}
} else if (this.comFlag == 2) {
for (int i = 0; i < listTemp.size(); i++) {
if (listTemp.get(i).getCommentsUser().getId() == top
.getTopicsUser().getId()) {
list.add(listTemp.get(i));
}
}
} else if (this.comFlag == 3) {
for (int i = 0; i < listTemp.size(); i++) {
if (listTemp.get(i).getIntegral() > 0) {
list.add(listTemp.get(i));
}
}
} else {
list = listTemp;
}
/* 先将list按楼层排序 */
if (list.size() > 1) {
this.QuickSort(list, 0, list.size() - 1);
}
this.nowPage = (this.nowPage == 0) ? 1 : this.nowPage;
/* 再将list按要求分页 */
this.pageBean = this.QueryCommentsForPage(10, nowPage, list);
this.listComment = this.pageBean.getListComments();
this.topic = top;
return "topic_go_ok";
}
/**
* 将从指定的topic里面获取到的comment进行按floor快速排序
*
* @param list
* @param first
* @param end
*/
public void QuickSort(List<Comments> list, int first, int end) {
/* 初始化各变量 */
int i = first;
int j = end;
Comments temp = list.get(i); // 用子表的第一个记录作为枢轴记录
while (i < j) { // 从表的两端交替向中间扫描
while (i < j && temp.getFloor() <= list.get(j).getFloor())
j--;
list.set(i, list.get(j)); // 采用替换而不是交换的方式进行操作
while (i < j && list.get(i).getFloor() <= temp.getFloor())
i++;
list.set(j, list.get(i)); // 采用替换而不是交换的方式进行操作
}
list.set(i, temp); // 将枢轴数值替换回L->R[i]
if (first < i - 1)
QuickSort(list, first, i - 1); // 对低子表进行递归
if (i + 1 < end)
QuickSort(list, i + 1, end); // 对高子表进行递归
}
/**
* 将从指定的topic里面获取到的comment进行分页处理
*
* @return
*/
public Pages QueryCommentsForPage(int pageSize, int nowPage,
List<Comments> listComment) {
int allRecords = listComment.size();
int totalPage = Pages.calculateTotalPage(pageSize, allRecords);// 总页数
final int currentoffset = Pages.currentPage_startRecord(pageSize,
nowPage);// 当前页的开始记录
final int length = pageSize;
final int currentPage = Pages.judgeCurrentPage(nowPage);
int toIndex = 0;
if (allRecords >= length + currentoffset) {
toIndex = currentoffset + length;
} else {
toIndex = allRecords;
}
List<Comments> subListComment = listComment.subList(currentoffset,
toIndex);
Pages pagebean = new Pages();
pagebean.setPageSize(pageSize);
pagebean.setAllRecords(allRecords);
pagebean.setCurrentPage(currentPage);
pagebean.setTotalPages(totalPage);
pagebean.setListComments(subListComment);
pagebean.init();
return pagebean;
}
public String GoEnd() throws Exception {
this.topic = this.topicService.find(topic.getId());
List<Comments> list = new ArrayList<Comments>();
list.addAll(this.topic.getTopicComments());
/* 先将list按楼层排序 */
if (list.size() > 1) {
this.QuickSort(list, 0, list.size() - 1);
}
this.listComment = list;
return "topic_goEnd_ok";
}
public String EndTopic() throws Exception {
Users user = (Users) session.getAttribute("tu");
String listfloor = request.getParameter("listFloor");
String[] str = listfloor.split(",");
int[] listFloor = new int[str.length];
for (int i = 0; i < listFloor.length; i++) {
listFloor[i] = Integer.parseInt(str[i]);
}
Topics top = this.topicService.find(topic.getId());
List<Comments> list = new ArrayList<Comments>();
List<Comments> listTemp = new ArrayList<Comments>();
listTemp.addAll(top.getTopicComments());
for (int i = 0; i < listTemp.size(); i++) {
int m = listTemp.get(i).getCommentsUser().getId();
int n = top.getTopicsUser().getId();
if (m != n) {
list.add(listTemp.get(i));
}
}
/* 先将list按楼层排序 */
if (list.size() > 1) {
this.QuickSort(list, 0, list.size() - 1);
}
this.listComment = list;
this.topicService.endTopic(listFloor, listComment);
user.setIntegral(user.getIntegral()+top.getIntegral()*20/100);
top.setTopicsUser(user);
top.setStatus(1);
this.topicService.update(top);
return "topic_end_ok";
}
public String getIndexHotTopic() throws Exception {
this.listTopic = this.topicService.getIndexHotTopic(10);
return "topic_getIndexHot_ok";
}
public String getIndexNiceTopic() throws Exception {
this.listTopic = this.topicService.getIndexNiceTopic(10);
return "topic_getIndexNice_ok";
}
public String getIndexFreshTopic() throws Exception {
this.listTopic = this.topicService.getIndexFreshTopic(10);
return "topic_getIndexFresh_ok";
}
public String getAllTopic() throws Exception {
this.pageBean = this.topicService.getAllForPages(10, nowPage);
this.listTopic = pageBean.getListTopics();
return "topic_getALL_ok";
}
public String GetHotTopic() throws Exception {
this.pageBean = this.topicService.getHotForPages(10, nowPage);
this.listTopic = pageBean.getListTopics();
return "topic_getHot_ok";
}
public String GetNiceTopic() throws Exception {
this.pageBean = this.topicService.getNiceForPages(10, nowPage);
this.listTopic = pageBean.getListTopics();
return "topic_getNice_ok";
}
public String Search() throws Exception {
this.pageBean = this.topicService.search(content, 5, nowPage);
this.listTopic = pageBean.getListTopics();
System.out.println(listTopic);
return "topic_search_ok";
}
public String goTopicByNews() throws Exception {
Users user = (Users) session.getAttribute("tu");
this.topicService.updateNews(this.tnew, user);
Topics top = this.topicService.find(topic.getId());
List<Comments> list = new ArrayList<Comments>();
List<Comments> listTemp = new ArrayList<Comments>();
listTemp.addAll(top.getTopicComments());
if (this.comFlag == 0) {
for (int i = 0; i < listTemp.size(); i++) {
if (listTemp.get(i).getStatus() == 0) {
list.add(listTemp.get(i));
}
}
} else if (this.comFlag == 2) {
for (int i = 0; i < listTemp.size(); i++) {
if (listTemp.get(i).getCommentsUser().getId() == top
.getTopicsUser().getId()) {
list.add(listTemp.get
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
本项目是一款基于SSH(Struts2+Spring+Hibernate)框架开发的IT技术学习交流论坛系统。它提供了一个类似于CSDN或ITeye的论坛平台,旨在促进技术学习与交流。系统界面设计简洁清爽,操作直观易用,确保了用户体验的友好性。项目包含527个文件,其中JavaScript文件80个,图片资源(包括png和gif)111个,Java源文件59个,编译后的class文件58个,JSP文件58个,打包的jar文件41个,HTML文件26个,CSS样式文件24个,以及XML配置文件23个。整个项目结构清晰,代码注释详尽,便于二次开发和学习研究。
资源推荐
资源详情
资源评论
收起资源包目录
基于SSH框架的IT技术学习交流论坛系统设计源码 (527个子文件)
TopicAction.class 11KB
UserAction.class 11KB
TopicServiceImpl.class 8KB
UserServiceImpl.class 7KB
Users.class 5KB
TopicDaoImpl.class 5KB
Pages.class 5KB
UserDaoImpl.class 5KB
CommentServiceImpl.class 4KB
CategoryAction.class 4KB
CategoryServiceImpl.class 4KB
FileUpload.class 4KB
AnnounceAction.class 4KB
HelpAction.class 4KB
Topics.class 3KB
TypeServiceImpl.class 3KB
TypeDaoImpl.class 3KB
CommentAction.class 3KB
AnnounceDaoImpl.class 3KB
AnnounceServiceImpl.class 3KB
CategoryDaoImpl.class 3KB
HelpServiceImpl.class 3KB
TypeAction.class 3KB
HelpDaoImpl.class 3KB
UploadFilter.class 2KB
Comments.class 2KB
CommentDaoImpl.class 2KB
Types.class 2KB
PageDaoImpl.class 2KB
Categorys.class 2KB
NewDaoImpl.class 2KB
News.class 1KB
SuperAdminInterceptor.class 1KB
AdminInterceptor.class 1KB
UserInterceptor.class 1KB
UEditorFilter.class 1KB
Announces.class 1KB
GradeDaoImpl.class 1KB
Helps.class 1KB
ResponseUtil.class 941B
TopicService.class 885B
CategoryService.class 800B
Grades.class 715B
TopicDao.class 662B
UserService.class 652B
AnnounceService.class 506B
UserDao.class 458B
AnnounceDao.class 427B
TypeDao.class 398B
HelpService.class 385B
CategoryDao.class 350B
HelpDao.class 306B
CommentService.class 290B
TypeService.class 270B
CommentDao.class 263B
NewDao.class 243B
PageDao.class 230B
GradeDao.class 151B
.classpath 3KB
org.eclipse.wst.common.component 450B
org.eclipse.wst.jsdt.ui.superType.container 49B
ueditor.css 41KB
ueditor.min.css 33KB
video-js.css 21KB
video-js.min.css 11KB
shCoreDefault.css 8KB
video.css 4KB
scrawl.css 4KB
codemirror.css 3KB
charts.css 3KB
image.css 2KB
attachment.css 2KB
index.css 2KB
emotion.css 2KB
music.css 2KB
dialogbase.css 2KB
edittable.css 1KB
background.css 1KB
template.css 1KB
manage.css 671B
register.css 580B
login.css 556B
manager_left.css 467B
help.css 389B
iframe.css 41B
vjs.eot 3KB
UEditorSnapscreen.exe 508KB
wface.gif 49KB
jxface2.gif 40KB
yface.gif 28KB
bface.gif 27KB
icons.gif 20KB
tface.gif 19KB
fface.gif 18KB
cface.gif 8KB
icons-all.gif 4KB
videologo.gif 2KB
cancelbutton.gif 1KB
button-bg.gif 1KB
lock.gif 1KB
共 527 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
沐知全栈开发
- 粉丝: 4743
- 资源: 3374
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功