/**
*
*/
package com.chen.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.chen.bean.Comments;
import com.chen.bean.News;
import com.chen.bean.Pages;
import com.chen.bean.Topics;
import com.chen.bean.Types;
import com.chen.bean.Users;
import com.chen.service.TopicService;
/**
* @author chenguoji
* @email chenguo_ji@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(l
没有合适的资源?快使用搜索试试~ 我知道了~
java web开发简单BBS论坛系统
共593个文件
class:116个
js:80个
png:75个
32 下载量 10 浏览量
2018-02-19
15:57:53
上传
评论 2
收藏 18.55MB ZIP 举报
温馨提示
java web开发简单BBS论坛系统,涉及的编程语言:Java | JavaScript | HTML 涉及的框架技术:Struts2 | Spring | Hibernate 其他技术:CSS | JQuery | Ajax | JSON | JSP | Servlet 有需要的可以作为学习参考
资源推荐
资源详情
资源评论
收起资源包目录
java web开发简单BBS论坛系统 (593个子文件)
TopicAction.class 11KB
TopicAction.class 11KB
UserAction.class 11KB
UserAction.class 11KB
TopicServiceImpl.class 8KB
TopicServiceImpl.class 8KB
UserServiceImpl.class 7KB
UserServiceImpl.class 7KB
Users.class 6KB
Users.class 5KB
TopicDaoImpl.class 5KB
Pages.class 5KB
TopicDaoImpl.class 5KB
Pages.class 5KB
UserDaoImpl.class 5KB
UserDaoImpl.class 5KB
CommentServiceImpl.class 4KB
CategoryAction.class 4KB
CommentServiceImpl.class 4KB
CategoryAction.class 4KB
CategoryServiceImpl.class 4KB
CategoryServiceImpl.class 4KB
FileUpload.class 4KB
FileUpload.class 4KB
AnnounceAction.class 4KB
AnnounceAction.class 4KB
HelpAction.class 4KB
HelpAction.class 4KB
Topics.class 3KB
Topics.class 3KB
TypeServiceImpl.class 3KB
TypeDaoImpl.class 3KB
CommentAction.class 3KB
TypeServiceImpl.class 3KB
TypeDaoImpl.class 3KB
CommentAction.class 3KB
AnnounceDaoImpl.class 3KB
AnnounceDaoImpl.class 3KB
AnnounceServiceImpl.class 3KB
AnnounceServiceImpl.class 3KB
CategoryDaoImpl.class 3KB
CategoryDaoImpl.class 3KB
HelpServiceImpl.class 3KB
HelpServiceImpl.class 3KB
TypeAction.class 3KB
TypeAction.class 3KB
HelpDaoImpl.class 3KB
HelpDaoImpl.class 3KB
UploadFilter.class 2KB
UploadFilter.class 2KB
Comments.class 2KB
Comments.class 2KB
CommentDaoImpl.class 2KB
CommentDaoImpl.class 2KB
Types.class 2KB
Types.class 2KB
PageDaoImpl.class 2KB
PageDaoImpl.class 2KB
Categorys.class 2KB
Categorys.class 2KB
NewDaoImpl.class 2KB
NewDaoImpl.class 2KB
News.class 1KB
News.class 1KB
SuperAdminInterceptor.class 1KB
SuperAdminInterceptor.class 1KB
AdminInterceptor.class 1KB
AdminInterceptor.class 1KB
UserInterceptor.class 1KB
UserInterceptor.class 1KB
UEditorFilter.class 1KB
UEditorFilter.class 1KB
Announces.class 1KB
Announces.class 1KB
GradeDaoImpl.class 1KB
GradeDaoImpl.class 1KB
Helps.class 1KB
Helps.class 1KB
ResponseUtil.class 943B
ResponseUtil.class 941B
TopicService.class 897B
TopicService.class 885B
CategoryService.class 810B
CategoryService.class 800B
Grades.class 717B
Grades.class 715B
TopicDao.class 670B
TopicDao.class 662B
UserService.class 662B
UserService.class 652B
AnnounceService.class 512B
AnnounceService.class 506B
UserDao.class 464B
UserDao.class 458B
AnnounceDao.class 432B
AnnounceDao.class 427B
TypeDao.class 402B
TypeDao.class 398B
HelpService.class 390B
HelpService.class 385B
共 593 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
普通网友
- 粉丝: 5
- 资源: 23
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功