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.domain.User; import com.epam.ipodromproject.service.CompetitionService; import com.epam.ipodromproject.service.MainService; import com.epam.ipodromproject.service.UserService; 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 RegisterCompetitionResultsController { @Autowired MainService mainService; @Autowired UserService userService; @Autowired CompetitionService competitionService; @RequestMapping(value = "registerResults", method = RequestMethod.GET) public String goToResults(Model model) { return "results"; } @RequestMapping(value = "getCompetitionsToRegisterPage", method = RequestMethod.GET) public String getCompetitionsByPage(@RequestParam("page") Integer page, @RequestParam("resultsPerPage") Integer resultsPerPage, Model model) { model.addAttribute("competitions", competitionService.getUnregisteredCompetitions(page, resultsPerPage)); model.addAttribute("firstNumber", (page - 1) * resultsPerPage); return "lists/competitionsToRegisterDropList"; } @RequestMapping(value = "registerCompetitionResult", method = RequestMethod.POST) @ResponseBody public String registerCompetitionRezult(@RequestParam("competitionID") Long competitionID, @RequestParam("placesTaken") String[] placesTaken) { User user = userService.getUserByUsername(SecurityContextHolder.getContext().getAuthentication().getName()); if (user.getEnabled() == false) { return "this_user_is_blocked"; } if (mainService.registerResult(competitionID, placesTaken)) { return "competition_result_registered_successfully"; } else { return "Places_not_ok"; } } }