Zerknijcie na kod poniżej i prosze o podpowiedz jaki uzyc value w @RequestMapping żeby po otwarciu strony i wpisaniu " / user / {id} wyswietliła sie lista wszystkich userow oraz w odpowiedniej lini wybrany user. W tym momencie po wpisaniu /user pokazuje sie lista ale znika jezeli dopisze jakies id po /.
@Controller
@RequestMapping("/user")
public class HomeController {
@Autowired
UserService userService;
@RequestMapping(value = "/", method = RequestMethod.GET)
public String showAllUser(ModelMap model) {
model.addAttribute("listall", userService.showAllUser());
return "user";
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String showChoseUser(@PathVariable int id, ModelMap model) {
model.addAttribute("selectedUser", userService.selectUser(id));
return "user";
}
}
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ page session="false"%>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>Wybrany user to : "${selectedUser.firstName}" "${selectedUser.lastName}"</h1>
<table>
<c:forEach items="${listall}" var="user">
<tr>
<td>"${user.id}""</td>
<td>"${user.firstName}"</td>
<td>"${user.login}""</td>
</tr>
</c:forEach>
</table>
</body>
</html>