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.ignite.controller; import com.ignite.dao.AccountDao; import com.ignite.dao.ClientDao; import com.ignite.domain.Account; import com.ignite.domain.Client; import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.annotation.Secured; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; @Controller public class ClientController { @Autowired ClientDao clientDao; @Autowired AccountDao accountDao; @RequestMapping(value = "/client", method = RequestMethod.GET) public ModelAndView client() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); List<Account> accounts = accountDao.getAccountsForClient(clientDao.getClient(name)); return new ModelAndView("client", "accountList", accounts); } @RequestMapping(value = "/addClient", method = RequestMethod.GET) public ModelAndView registerClient() { return new ModelAndView("addClient"); } @RequestMapping(value = "/addAccount/{clientName}", method = RequestMethod.GET) public ModelAndView registerAccount(@PathVariable String clientName) { Account account = new Account(); Client client = new Client(); client.setLogin(clientName); account.setOwner(client); account.setBalance(0); accountDao.saveAccount(account); List<Client> clients = clientDao.getClients(); return new ModelAndView("teller", "clientList", clients); } }