viewcategorycontroller.java

来自「java写的blog」· Java 代码 · 共 65 行

JAVA
65
字号
/*
 * Created on 2004-10-4
 * Author: Xuefeng, Copyright (C) 2004, Xuefeng.
 */
package org.crystalblog.web;

import java.util.*;
import javax.servlet.http.*;

import org.crystalblog.domain.*;
import org.crystalblog.logic.Facade;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

/**
 * To view the specified category.
 * 
 * @author Xuefeng
 */
public class ViewCategoryController implements Controller {

    private SkinManager skin;
    private Facade facade;

    public void setSkinManager(SkinManager skin) { this.skin = skin; }
    public void setFacade(Facade facade) { this.facade = facade; }

    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        int categoryId = Integer.parseInt(request.getParameter("categoryId"));
        String s_page = request.getParameter("page");
        int page = 1;
        if(s_page!=null && !s_page.equals(""))
            page = Integer.parseInt(s_page);

        Account account = facade.getAccountByCategory(categoryId);
        int accountId = account.getAccountId();
        List categories = facade.getCategories(accountId);
        List articles = facade.getArticlesByCategory(categoryId, account.getMaxPerPage(), page);
        int total = facade.getArticlesCount(categoryId);
        List links = facade.getAllLinks(accountId);

        Map map = new HashMap();
        map.put("account", account);
        map.put("categories", categories);
        Iterator it = categories.iterator();
        while(it.hasNext()) {
            Category c = (Category)it.next();
            if(c.getCategoryId()==categoryId) {
                map.put("category", c);
                break;
            }
        }
        map.put("articles", articles);
        map.put("links", links);
        map.put("total", new Integer(total));
        int per = account.getMaxPerPage();
        int pages = total/per + (total%per==0 ? 0 : 1);
        map.put("page", new Integer(page));
        map.put("pages", new Integer(pages));
        return new ModelAndView(skin.getSkin(account.getSkinId()) + "category.html", map);
    }

}

⌨️ 快捷键说明

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