Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.local.ask.controller.spring; import static com.local.ask.controller.spring.BaseController.REDIRECT_HOME; import com.local.ask.model.Question; import java.util.Collections; import java.util.List; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; /** * * @author Olayinka */ @Controller public class HomeController extends BaseController { @RequestMapping(value = "/") public String loadDefaultPage(Model m) { return REDIRECT_HOME; } @RequestMapping(value = "/home", method = RequestMethod.GET) public String loadHomeForm(Model m) { m.addAttribute("questions", dbHelper.getRecentQuestions()); m.addAttribute("tab", 0); m.addAttribute("tags", dbHelper.getRecentTags()); m.addAttribute("qtag", false); return "home"; } @RequestMapping(value = "/home/hottest", method = RequestMethod.GET) public String loadHomeHottestQuestionForm(Model m) { List<Question> questions = dbHelper.getRecentForHottestQuestions(); Collections.sort(questions, hottestComparator); m.addAttribute("qtag", false); m.addAttribute("questions", questions); m.addAttribute("tags", dbHelper.getRecentTags()); m.addAttribute("tab", 1); return "home"; } @RequestMapping(value = "/error/404", method = RequestMethod.GET) public String loadError404(Model m) { return "404"; } }