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

📄 viewcategorycontroller.java

📁 java写的blog
💻 JAVA
字号:
/*
 * 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -