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.epam.ipodromproject.controller; import com.epam.ipodromproject.service.BetService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; 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.bind.annotation.ResponseBody; /** * * @author Oleh */ @Controller public class ArchivedBetsController { @Autowired BetService betService; @RequestMapping(value = "archiveBets", method = RequestMethod.GET) public String goToArchive() { return "archive"; } @RequestMapping(value = "getArchiveBetsPage", method = RequestMethod.GET) public String getArchivePage(@RequestParam(value = "page") Integer page, @RequestParam(value = "resultsPerPage") Integer resultsPerPage, Model model) { String username = SecurityContextHolder.getContext().getAuthentication().getName(); int totalPages = (int) betService.getTotalArchiveBetsPagesMadeByUser(username, resultsPerPage); if (page < 1) { page = 1; } else if (page > totalPages) { page = totalPages; } model.addAttribute("bets", betService.getArchivedBetsPageMadeByUser(username, page, resultsPerPage)); return "lists/archiveBetsDropList"; } @RequestMapping(value = "getTotalArchiveBetsPages", method = RequestMethod.GET) @ResponseBody public int getTotalArchiveBetsPages(@RequestParam(value = "resultsPerPage") Integer resultsPerPage) { String username = SecurityContextHolder.getContext().getAuthentication().getName(); return (int) betService.getTotalArchiveBetsPagesMadeByUser(username, resultsPerPage); } }