⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 topicaction.java

📁 struts+hibernate BBS mysql数据库 功能基本齐全
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		forumtopicreply.setLocked(Byte.valueOf(locked));
		if (!El.getEl().getForumUserMgr().ReplyTopic(forumtopicreply)) {
			ActionErrors errors = new ActionErrors();
			errors.add("", new ActionError("forum.reply.errors"));
			saveErrors(request, errors);
			//System.out.println("错误啦");
			return (new ActionForward(mapping.getInput()));
		}
		// 获取 forumTopic reply + 1
		ForumTopic fourmTopic = El.getEl().getTopicMgr().getTopicId(topicId);
		fourmTopic.setReply(fourmTopic.getReply() + 1);
		El.getEl().getTopicMgr().saveTopic(fourmTopic);
		//System.out.println("reply:::::::::::::::::+1");
		// 读出TOPIC FROM PIECE
		List<Forumtopicreply> falist = El.getEl().getTopicMgr().findTopicReply(
				topicId);
		request.setAttribute("reply", falist);
		request.setAttribute("pieceId", pieceId);
		request.setAttribute("topicId", topicId);
		request.setAttribute("pieceTopic", El.getEl().getTopicMgr()
				.findPieceTopic(topicId));

		// 构造位置,由showTopic..TopicAction.负责
		return this.showTopic(mapping, form, request, response);
		//return mapping.findForward("showTopic");
	}

	/*
	 * 1,如果返回fa是NULL,则没有文章. 2,构造位置. 3,获取回复. 4,获取引用片段. (non-Javadoc)
	 * 
	 * @see com.elan.forum.actions.topic.TopicBaseAction#quoteReply(org.apache.struts.action.ActionMapping,
	 *      org.apache.struts.action.ActionForm,
	 *      javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected ActionForward quoteReply(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		Integer topicId = getTopicId(request);
		ForumTopic fa = El.getEl().getTopicMgr().findPieceTopic(topicId);
		if (fa == null) {
			ActionErrors errors = new ActionErrors();
			// 1 无此帖子
			errors.add("", new ActionError("topic.no.find"));
			saveErrors(request, errors);
			return mapping.findForward("topicNotFind");
		}
		// 2 //构造路径
		/*String position = constructPosition(request, fa.getPiece().getId(), fa
				.getPiece().getName(), fa.getId(), fa.getTitle());
		request.setAttribute("position", position);

		// 3 获取回复的帖子
		List<Forumtopicreply> falist = El.getEl().getTopicMgr().findTopicReply(
				topicId);
		ForumUser topicAuthor = fa.getForumUser();
		request.setAttribute("topicAuthor", topicAuthor);
		request.setAttribute("replyList", falist);
		request.setAttribute("topic", fa);
		request.setAttribute("pieceId", fa.getPiece().getId());*/
		//TEST://System.out.println("pieceId:" + fa.getPiece().getId());
		// 4
		String quoteStr = request.getParameter("quoteId");
		Integer quoteId;
		if (quoteStr != null) {
			quoteId = (Integer.valueOf(quoteStr));
			if (topicId.intValue() != quoteId.intValue()) {
				Forumtopicreply ftr = El.getEl().getTopicMgr()
						.findTopicReplyById(quoteId);
				if (ftr != null) {
					request.setAttribute("quoteReply", "以下是引用 ["
							+ ftr.getAuthor() + "] 片段:<br>" + ftr.getText());
				}
			}
		} else {
			request.setAttribute("quoteReply", "以下是引用 [" + fa.getAuthor()
					+ "] 片段:<br>" + fa.getText());
		}
		//System.out.println("没有任何的问题哦!");
		//return mapping.findForward("showTopic");
		//return new ActionForward("topic.do?action=showTopic&topicId=" + topicId);
		return this.showTopic(mapping, form, request, response);
	}

	/**
	 * 返回热门帖子
	 * 
	 * @return ActionForward
	 */
	@Override
	protected ActionForward hotTopic(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		Integer pieceId = this.getPieceId(request);
		String pieceName = null;
		Integer topicCount = Constents.hotTopicCount;
		if (pieceId != null) {
			pieceName = El.getEl().getTopicMgr().getForumPieceById(pieceId)
					.getName();
			this.setAttribute(request, "pieceId", pieceId);
		}
		String position = this.constructPosition(request, pieceId, pieceName,
				null, null);
		if (pieceId != null) {
			position += "<a href=\"" + request.getContextPath()
					+ "/forum/topic.do?action=hotTopic&pieceId=" + pieceId
					+ "\">热门主题</a>";
		} else {
			position += "<a href=\"" + request.getContextPath()
					+ "/forum/topic.do?action=hotTopic\">热门主题</a>";
		}
		List<ForumTopic> list = El.getEl().getTopicMgr().getHotTopic(pieceId,
				null, topicCount);
		this.setAttribute(request, "position", position);
		this.setAttribute(request, "topicCount", topicCount);
		this.setAttribute(request, "topicList", list);

		return mapping.findForward("hotTopic");
	}

	/**
	 * 
	 * 返回新发的帖子
	 * 
	 * 1, 返回的是全部的新帖子(分页) 2, 返回的是piece下面的帖子
	 * 
	 * @return ActionForward
	 */
	@Override
	protected ActionForward newPostTopic(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		Integer pieceId = this.getPieceId(request);
		String pieceName = null;
		if (pieceId != null) {
			pieceName = El.getEl().getTopicMgr().getForumPieceById(pieceId)
					.getName();
			this.setAttribute(request, "pieceId", pieceId);
		}
		List<ForumTopic> list = El.getEl().getTopicMgr().getNewPostTopic(
				pieceId, null, Constents.newPostTopicPageSize);
		String position = this.constructPosition(request, pieceId, pieceName,
				null, null);
		if (pieceId != null) {
			position += "<a href=\"" + request.getContextPath()
					+ "/forum/topic.do?action=newPostTopic&pieceId=" + pieceId
					+ "\">新帖</a>";
		} else {
			position += "<a href=\"" + request.getContextPath()
					+ "/forum/topic.do?action=newPostTopic\">新帖</a>";
		}

		this.setAttribute(request, "position", position);
		this.setAttribute(request, "topicList", list);
		this.setAttribute(request, "pageSize", Constents.newPostTopicPageSize);
		this.setAttribute(request, "topicCount", Constents.newPostTopicCount);
		return mapping.findForward("newPostTopic");
	}

	/**
	 * 1)查询 搜索
	 */
	@Override
	protected ActionForward search(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		//总页数
		Integer pageCount = 0;
		//页码大小
		Integer pageSize = Constents.searchPageSize;
		//送搜索出来的记录
		Integer topicCount = 0;
		//当前页面
		Integer page = this.getPage(request);//如果< 0 则为1

		//获取数据
		String pieceName = null;
		Integer hotReal = null; // 全部范围,1最新,2新华
		Integer moduleId = this.getModuleId(request);
		Integer pieceId = this.getPieceId(request);
		Integer topicId = this.getTopicId(request);
		Integer precision = 2; // 模糊搜索
		
		if (pieceId != null && pieceId > 0) {
			Forumpiece fe = El.getEl().getTopicMgr().getForumPieceById(pieceId);
			pieceName = fe == null ? "" : fe.getName();
		}
		String position = this.constructPosition(request, pieceId, pieceName,
				null, null);
		if (pieceId != null && pieceId > 0) {
			position += "<a href=\"" + request.getContextPath()
					+ "/forum/topic.do?action=search&pieceId=" + pieceId
					+ "\">论坛搜索</a>";
		} else {
			position += "<a href=\"" + request.getContextPath()
					+ "/forum/topic.do?action=search\">论坛搜索</a>";
		}
		String isSearch = request.getParameter("isSearch");
		String fastSearch = request.getParameter("fastSearch");
		// 获取module,piece信息,以用于在JSP中的select控件使用
		List<Forummodule> listModule = El.getEl().getTopicMgr().getModule();
		List<Forumpiece> listPiece = El.getEl().getTopicMgr().getpiece();

		// 快速搜索
		if ("true".equals(fastSearch)) {
			String keyword = request.getParameter("keyword");
			String topicName = keyword;
			String author = null;
			Timestamp startTime = null;
			Timestamp endTime = null;
			
			Map<String, Object> map = null;
			List<ForumTopic> listTopic = null;
			
			if (topicName != null && !"".equals(topicName.trim())) {
				 map = El.getEl().getTopicMgr().search(moduleId, pieceId,
						topicId, hotReal, topicName, author, startTime,
						endTime, precision, page, pageSize);
				 if(map != null) {
					 listTopic = (List<ForumTopic>) map.get("listTopic");
					 topicCount = (Integer) map.get("topicCount");
					 page = (Integer) map.get("page");
					 pageSize = (Integer) map.get("pageSize");
					 pageCount = (Integer) map.get("pageCount");
				 }
			} else {
				ActionErrors errors = new ActionErrors();
				errors.add("", new ActionError("search keyword must not null"));
				saveErrors(request, errors);
			}

			this.setAttribute(request, "position", position);
			this.setAttribute(request, "listModule", listModule);
			this.setAttribute(request, "listPiece", listPiece);
			this.setAttribute(request, "listTopic", listTopic);
			this.setAttribute(request, "pieceId", pieceId);
			this.setAttribute(request, "moduleId", moduleId);
			this.setAttribute(request, "topicId", topicId);
			this.setAttribute(request, "page", page);
			this.setAttribute(request, "pageSize", pageSize);
			this.setAttribute(request, "topicCount", topicCount);
			this.setAttribute(request, "hotReal", hotReal);
			
			return mapping.findForward("search");
		}
		// 1
		if ("true".equals(isSearch)) {

			if (request.getParameter("precision") != null) {
				precision = Integer.valueOf(request.getParameter("precision"));
			}
			if (request.getParameter("topic") != null
					&& !"".equals(request.getParameter("topic").trim())) {
				topicId = Integer.valueOf(request.getParameter("topic"));
			}
			
			if (request.getParameter("hotReal") != null
					&& !"".equals((request.getParameter("hotReal").trim()))) {
				hotReal = Integer.valueOf(request.getParameter("hotReal"));
			}
			String topicName = null;
			if (request.getParameter("topicName") != null
					&& !"".equals((request.getParameter("topicName").trim()))) {
				topicName = request.getParameter("topicName");
			}
			String author = null;
			if (request.getParameter("author") != null
					&& !"".equals((request.getParameter("author").trim()))) {
				author = request.getParameter("author");
			}

			Timestamp startTime = this.createTimestamp(request, 1);
			Timestamp endTime = this.createTimestamp(request, 2);
			System.out.println("topic moduleId " + moduleId);
			System.out.println("topic pieceId " + pieceId);
			System.out.println("topic topicId " + topicId);
			System.out.println("topic topicName " + topicName);
			System.out.println("topic author " + author);
			System.out.println("topic hotReal " + hotReal);
			if ((moduleId == null || -1 == moduleId)
					&& (pieceId == null || -1 == pieceId ) && topicId == null
					&& topicName == null 
					&& author == null
					&& (hotReal == null|| -1 == hotReal)) {
				ActionErrors errors = new ActionErrors();
				errors.add("", new ActionError("choose a one"));
				saveErrors(request, errors);
				this.setAttribute(request, "position", position);
				this.setAttribute(request, "listModule", listModule);
				this.setAttribute(request, "listPiece", listPiece);
				this.setAttribute(request, "moduleId", moduleId);
				this.setAttribute(request, "topicId", topicId);
				this.setAttribute(request, "pieceId", pieceId);
				this.setAttribute(request, "page", page);
				this.setAttribute(request, "pageSize", pageSize);
				this.setAttribute(request, "topicCount", topicCount);
				this.setAttribute(request, "hotReal", hotReal);
				
				return mapping.findForward("search");
			}
			Map<String, Object> map = El.getEl().getTopicMgr().search(
					moduleId, pieceId, topicId, hotReal, topicName, author,
					startTime, endTime, precision, page, pageSize);
			List<ForumTopic> listTopic = null;
			if(map != null) {
				System.out.println("sdfsdfsdfsdfdsfsfds");
				listTopic = (List<ForumTopic>) map.get("listTopic");
				topicCount = (Integer) map.get("topicCount");
				page = (Integer) map.get("page");
				pageSize = (Integer) map.get("pageSize");
				pageCount = (Integer) map.get("pageCount");
			}
			
			System.out.println("topicCount::" + topicCount);
			this.setAttribute(request, "position", position);
			this.setAttribute(request, "listModule", listModule);
			this.setAttribute(request, "listPiece", listPiece);
			this.setAttribute(request, "listTopic", listTopic);
			this.setAttribute(request, "pieceId", pieceId);
			this.setAttribute(request, "moduleId", moduleId);
			this.setAttribute(request, "topicId", topicId);
			this.setAttribute(request, "page", page);
			this.setAttribute(request, "pageSize", pageSize);
			this.setAttribute(request, "topicCount", topicCount);
			this.setAttribute(request, "hotReal", hotReal);
			
			return mapping.findForward("search");
		}

		this.setAttribute(request, "position", position);
		this.setAttribute(request, "listModule", listModule);
		this.setAttribute(request, "listPiece", listPiece);
		this.setAttribute(request, "pieceId", pieceId);
		this.setAttribute(request, "moduleId", moduleId);
		this.setAttribute(request, "topicId", topicId);
		this.setAttribute(request, "topicCount", topicCount);
		this.setAttribute(request, "page", page);
		this.setAttribute(request, "pageSize", pageSize);
		this.setAttribute(request, "hotReal", hotReal);
		
		return mapping.findForward("search");
	}

	@Override
	protected ActionForward essence(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		Integer pageSize = Constents.essencePageSize;
		Integer topicCount = 0;
		String pieceName = null;
		Integer pieceId = this.getPieceId(request); // 有可能返回的是空的值
		if (pieceId != null) {
			pieceName = El.getEl().getTopicMgr().getForumPieceById(pieceId)
					.getName();
			this.setAttribute(request, "pieceId", pieceId);
		}
		String position = this.constructPosition(request, pieceId, pieceName,
				null, null);
		if (pieceId != null) {
			position += "<a href=\"" + request.getContextPath()
					+ "/forum/topic.do?action=essence&pieceId=" + pieceId
					+ "\">精华帖子</a>";
		} else {
			position += "<a href=\"" + request.getContextPath()
					+ "/forum/topic.do?action=essence\">精华帖子</a>";
		}
		List<ForumTopic> listEssenceTopic = El.getEl().getTopicMgr()
				.getEssenceTopic(pieceId);
		topicCount = null != listEssenceTopic ? listEssenceTopic.size() : 0;

		this.setAttribute(request, "position", position);
		this.setAttribute(request, "pageSize", pageSize);
		this.setAttribute(request, "topicCount", topicCount);
		this.setAttribute(request, "listEssenceTopic", listEssenceTopic);

		return mapping.findForward("essence");
	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return super.execute(mapping, form, request, response);
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -