-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUserController.java
More file actions
38 lines (32 loc) · 1.12 KB
/
UserController.java
File metadata and controls
38 lines (32 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.example.LoginPlusSecurity.controller;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import com.example.LoginPlusSecurity.model.User;
import com.example.LoginPlusSecurity.service.UserService;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@GetMapping("/{username}")
public String getUserDetails(@PathVariable String username, Model model) {
Optional<User> user = userService.getUserByName(username);
if (user.isPresent()) {
model.addAttribute("user", user.get());
return "user-details";
}
else {
model.addAttribute("error", "User not found");
return "error";
}
}
// @GetMapping("")
// public String userProfile() {
//
// }
}