ash.resourcemanager.spring.controllers.IndexController.java Source code

Java tutorial

Introduction

Here is the source code for ash.resourcemanager.spring.controllers.IndexController.java

Source

/*
 * 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 ash.resourcemanager.spring.controllers;

import ash.resourcemanager.hibernate.GenericDAO;
import ash.resourcemanager.hibernate.pojo.Assignment;
import ash.resourcemanager.hibernate.pojo.Employee;
import ash.resourcemanager.hibernate.pojo.Project;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author Ash
 */
@Controller
@SessionAttributes
public class IndexController {
    @RequestMapping(value = "/index.htm", method = RequestMethod.GET)
    public ModelAndView showHomePage() {
        ModelAndView modelAndView = new ModelAndView("index");
        GenericDAO<Project> projectsDAO = new GenericDAO<Project>(Project.class);
        GenericDAO<Assignment> assignmentsDAO = new GenericDAO<Assignment>(Assignment.class);
        GenericDAO<Employee> employeeDAO = new GenericDAO<Employee>(Employee.class);

        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String date = sdf.format(cal.getTime());

        modelAndView.addObject("date", date);
        modelAndView.addObject("projects", projectsDAO.getAll());
        modelAndView.addObject("employees", employeeDAO.getAll());

        return modelAndView;
    }
}