📄 homecontroller.java
字号:
/*
* Created on 2004-10-3
* Author: Xuefeng, Copyright (C) 2004, Xuefeng.
*/
package org.crystalblog.web;
import java.util.*;
import org.crystalblog.domain.Account;
import org.crystalblog.logic.Facade;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.*;
/**
* This is the home page of the blog. URL=/home.c?accountId=###
*
* @author Xuefeng
*/
public class HomeController 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 {
// get the parameters:
int accountId = Integer.parseInt(request.getParameter("accountId"));
String s_page = request.getParameter("page");
int page = 1;
if(s_page!=null && !s_page.equals(""))
page = Integer.parseInt(s_page);
// get the model:
Account account = facade.getAccount(accountId);
List categories = facade.getCategories(accountId);
List articles = facade.getArticles(accountId, account.getMaxPerPage(), page);
List links = facade.getAllLinks(accountId);
// create model:
Map map = new HashMap();
map.put("account", account);
map.put("categories", categories);
map.put("links", links);
map.put("articles", articles);
int all = account.getArticles();
int per = account.getMaxPerPage();
int pages = all/per + (all%per==0 ? 0 : 1);
map.put("pages", new Integer(pages));
map.put("page", new Integer(page));
return new ModelAndView(skin.getSkin(account.getSkinId()) + "home.html", map);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -