source: source/src/main/java/com/example/db/controller/UsersController.java

Last change on this file was bc0eeb4, checked in by Evgenija2000 <eva_nikolaevska@…>, 2 years ago

all files

  • Property mode set to 100644
File size: 1.1 KB
Line 
1package com.example.db.controller;
2
3import com.example.db.model.OnlineStores;
4import com.example.db.model.Users;
5import com.example.db.service.UsersService;
6import org.springframework.stereotype.Controller;
7import org.springframework.ui.Model;
8import org.springframework.web.bind.annotation.GetMapping;
9import org.springframework.web.bind.annotation.RequestMapping;
10import org.springframework.web.bind.annotation.RequestParam;
11
12import java.util.List;
13
14@Controller
15@RequestMapping("/users")
16public class UsersController {
17 private final UsersService usersService;
18
19 public UsersController(UsersService usersService) {
20 this.usersService = usersService;
21 }
22
23 @GetMapping
24 public String getUsers(@RequestParam(required = false) String error, Model model){
25 if(error!=null && !error.isEmpty()){
26 model.addAttribute("hasError",true);
27 model.addAttribute("error",error);
28 }
29 else{
30 List<Users> users = this.usersService.findAll();
31 model.addAttribute("users", users);
32
33 }
34 return "users";
35 }
36}
Note: See TracBrowser for help on using the repository browser.