mainjsp.java

来自「社区文章采用的是平板、树形自由选择的两种展示方式」· Java 代码 · 共 105 行

JAVA
105
字号
/* 
 * Created on 2007-5-13
 * Last modified on 2007-11-9
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.view.jsp;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yeqiangwei.club.param.TopicParameter;
import com.yeqiangwei.club.service.ServiceLocator;
import com.yeqiangwei.club.service.ServiceWrapper;
import com.yeqiangwei.club.service.counter.CountService;
import com.yeqiangwei.club.service.forum.ForumService;
import com.yeqiangwei.club.model.Counters;
import com.yeqiangwei.club.model.Forum;
import com.yeqiangwei.club.model.Topic;
import com.yeqiangwei.club.service.topic.TopicService;
import com.yeqiangwei.club.util.BeanLocator;
import com.yeqiangwei.club.util.BeanUtils;
import com.yeqiangwei.club.view.model.CounterView;
import com.yeqiangwei.club.view.model.ForumView;
import com.yeqiangwei.club.view.model.TopicView;
import com.yeqiangwei.util.Validator;

public class MainJsp extends BaseJsp{

	public MainJsp(HttpServletRequest request, HttpServletResponse response) {
		super(request, response);
	}
	
	public List<ForumView> findTopForums(int rows){
		List<Forum> mlist = this.getForumService().findTops(rows);
		List<ForumView> list = BeanUtils.copyList(mlist,BeanLocator.FORUMVIEW);
		return list;
	}
	
	public List<TopicView> findOrderBy(int rows, byte orderBy){
		TopicParameter param = new TopicParameter();
		param.setForumId(null);
		param.setPage(1);
		param.setRows(rows);
		param.setOrderBy(orderBy); //order by topicId desc
		param.setIsDeleted(new Boolean(false));
		List<Topic> mlist = this.getTopicService().findByParameter(param);
		List<TopicView> list = BeanUtils.copyList(mlist,BeanLocator.TOPICVIEW);
		return list;
	}
	
	public List<TopicView> getViewingTopics(int rows){
		List<Topic> list = this.getTopicService().getViewingTopics();
		List<TopicView> vlist = null;
		if(!Validator.isEmpty(list)){
			vlist = new ArrayList<TopicView>();
			for(int i=0; i<list.size(); i++){
				if(i==rows){
					break;
				}
				TopicView view = new TopicView();
				BeanUtils.copyProperties(view, list.get(i));
				vlist.add(view);
			}
		}
		return vlist;
	}
	
	
	public List<TopicView> findTopic(int rows){
		return this.findOrderBy(rows,(byte)2);
	}

	public List<TopicView> findOrderByTopicId(int rows){
		return this.findOrderBy(rows,(byte)2);
	}
	
	public List<TopicView> findOrderByReplyId(int rows){
		return this.findOrderBy(rows,(byte)3);
	}

	public CounterView getCounterView(){
		CounterView v = new CounterView();
		Counters m = this.getCountService().findOnlyPublic();
		if(!Validator.isEmpty(m)){
			BeanUtils.copyProperties(v,m);
		}
		return v;
	}
	
	private CountService getCountService() {
		return ServiceWrapper.<CountService>getSingletonInstance(ServiceLocator.COUNT);
	}
	
	private ForumService getForumService() {
		return ServiceWrapper.<ForumService>getSingletonInstance(ServiceLocator.FORUM);
	}
	
	public TopicService getTopicService() {
		return ServiceWrapper.<TopicService>getSingletonInstance(ServiceLocator.TOPIC);
	}
}

⌨️ 快捷键说明

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