Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Andras Madi-Szabo
Added: May 19, 2020 11:16 AM
Views: 9
Tags: beci vizsga
  1. import com.example.demo.services.UserService;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.stereotype.Controller;
  4. import org.springframework.ui.Model;
  5. import org.springframework.web.bind.annotation.GetMapping;
  6. import org.springframework.web.bind.annotation.RequestParam;
  7.  
  8. @Controller
  9. public class MainController {
  10.  
  11.   private UserService userService;
  12.  
  13.   @Autowired
  14.   public MainController(UserService userService) {
  15.     this.userService = userService;
  16.   }
  17.  
  18.   @GetMapping("/")
  19.   public String getMainPage(Model model) {
  20.     model.addAttribute("users", userService.findAll());
  21.     return "index";
  22.   }
  23.  
  24.   @GetMapping("/age")
  25.   public String getMainPage(Model model,
  26.                             @RequestParam(required = false) int age) {
  27.     model.addAttribute("users", userService.getUsersAgeGreaterThan(age));
  28.     return "index";
  29.   }
  30.  
  31. }