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 | |
---|
1 | package com.example.db.controller;
|
---|
2 |
|
---|
3 | import com.example.db.model.OnlineStores;
|
---|
4 | import com.example.db.model.Users;
|
---|
5 | import com.example.db.service.UsersService;
|
---|
6 | import org.springframework.stereotype.Controller;
|
---|
7 | import org.springframework.ui.Model;
|
---|
8 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
9 | import org.springframework.web.bind.annotation.RequestMapping;
|
---|
10 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
11 |
|
---|
12 | import java.util.List;
|
---|
13 |
|
---|
14 | @Controller
|
---|
15 | @RequestMapping("/users")
|
---|
16 | public 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.