SpringbootでJPAを使用してデータを1件取得、そのデータをセッションに登録し、thymeleafを使用して画面(detail.html)に表示するという事を勉強している初心者です。
データは取得出来ているのですが、画面には項目名だけが表示され、データが表示されません。
色々ネットで調べて試してみたのですが、解決に至りませんでした。
また、1件表示する場合の書き方もこれで良いのか分からないので、宜しければ教えて下さい。宜しくお願いします。
@Controller
@RequestMapping("/room")
@SessionAttributes("update")
public UpdateRoomController {
@Autowired
ShowRoomDetailService showRoomDetailService;
@GetMapping("/detail/{Id}")
public String showRoomDetail(@PathVariable Integer Id, Model model) {
Room room = showRoomDetailService.getRoomDetail(Id);
model.addAttribute("update", room);
return "detail";
}
}
■detail.html
<!DOCTYPE html> <html lang="ja" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <h1>詳細</h1> <table border="1"> <tr> <th>ID</th> <th>名前</th> </tr> <tr th:each="room : ${session.update}" th:object="${room}"> <td th:text="*{id}"></td> <td th:text="*{name}"></td> </tr> </table> </body> </html>回答1件
あなたの回答
tips
プレビュー