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 by.bsuir.finance.controllers; import by.bsuir.finance.domain.Salary; import by.bsuir.finance.service.salary.SalaryService; import by.bsuir.finance.service.user.UserInfoService; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; /** * * @author igor */ @Controller @RequestMapping(value = "/salary") public class SalaryController { @Autowired private SalaryService salaryService; @Autowired private UserInfoService infoService; @RequestMapping(value = "/view") public ModelAndView view() { ModelAndView model = new ModelAndView("salary/view"); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); //get logged in username List<Salary> salarys = salaryService.findByUsername(name); model.addObject("salaries", salarys); return model; } @RequestMapping(value = "/viewall") public ModelAndView viewall() { ModelAndView model = new ModelAndView("salary/viewall"); model.addObject("salaries", salaryService.findAll()); return model; } }