From 01ffb883584a21badf76119bfae1481ea410c51a Mon Sep 17 00:00:00 2001 From: a-kawaguchi <26-a-kawaguchi-kyoeisystems@it-college.co.jp> Date: Tue, 29 Sep 2026 09:40:34 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=AD=E3=82=B0=E3=82=A4=E3=83=B3=E8=80=85?= =?UTF-8?q?=E3=81=AE=E5=90=8D=E5=89=8D=E3=81=AE=E8=A1=A8=E7=A4=BA=E3=81=8A?= =?UTF-8?q?=E3=82=88=E3=81=B3=E4=B8=8E=E3=81=88=E3=82=89=E3=82=8C=E3=81=9F?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=83=AB=E3=81=AB=E3=82=88=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=83=88=E3=83=83=E3=83=97=E3=83=A1=E3=83=8B=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E3=81=AE=E8=A1=A8=E7=A4=BA=E5=86=85=E5=AE=B9=E3=82=92=E5=88=86?= =?UTF-8?q?=E3=81=91=E3=82=8B=E6=A9=9F=E8=83=BD=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/controller/LoginController.java | 40 ++++++++++++++++--- src/main/resources/templates/topmenu.html | 17 +++++--- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/example/demo/controller/LoginController.java b/src/main/java/com/example/demo/controller/LoginController.java index 4e469fc..49859cd 100644 --- a/src/main/java/com/example/demo/controller/LoginController.java +++ b/src/main/java/com/example/demo/controller/LoginController.java @@ -1,8 +1,11 @@ package com.example.demo.controller; +import java.util.List; + import jakarta.servlet.http.HttpSession; import jakarta.validation.Valid; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -11,7 +14,9 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import com.example.demo.entity.AccountEntity; +import com.example.demo.entity.Employee; import com.example.demo.form.LoginForm; +import com.example.demo.repository.EmployeeRepository; import com.example.demo.service.LoginService; import lombok.RequiredArgsConstructor; @@ -21,12 +26,20 @@ import lombok.RequiredArgsConstructor; public class LoginController { private final LoginService loginService; + @Autowired + private EmployeeRepository employeeRepository; + // Boot起動直後にログイン画面に移動する用のメソッド @GetMapping("/") - public String index(HttpSession session) { + public String index(Model model,HttpSession session) { if (session.getAttribute("loginEmployee") != null) { - return "redirect:/topmenu"; + if(session.getAttribute("EmployeeId") != null) { + + List emrp = employeeRepository.findByEmployeeId((Integer)session.getAttribute("EmployeeId") ); + model.addAttribute("LoginName",emrp.getFirst().getEmployeeName()); + } + return "topmenu"; } return "redirect:/login"; } @@ -34,7 +47,12 @@ public class LoginController { @GetMapping("/login") public String loginForm(Model model, HttpSession session) { if (session.getAttribute("loginEmployee") != null) { - return "redirect:/topmenu"; + if(session.getAttribute("EmployeeId") != null) { + + List emrp = employeeRepository.findByEmployeeId((Integer)session.getAttribute("EmployeeId") ); + model.addAttribute("LoginName",emrp.getFirst().getEmployeeName()); + } + return "topmenu"; } model.addAttribute("loginForm", new LoginForm()); @@ -61,7 +79,13 @@ public class LoginController { } session.setAttribute("loginEmployee", accountEntity); - return "redirect:/topmenu"; + + List emrp = employeeRepository.findByEmployeeId(accountEntity.getEmployee().getEmployeeId()); + model.addAttribute("LoginName",emrp.getFirst().getEmployeeName()); + session.setAttribute("EmployeeId", accountEntity.getEmployee().getEmployeeId()); + + + return "topmenu"; } // ログアウト処理 @@ -73,7 +97,13 @@ public class LoginController { // 各画面からトップメニューへの遷移用 @GetMapping("/topmenu") - public String showTopMenu() { + public String showTopMenu(Model model,HttpSession session) { + + if(session.getAttribute("EmployeeId") != null) { + + List emrp = employeeRepository.findByEmployeeId((Integer)session.getAttribute("EmployeeId") ); + model.addAttribute("LoginName",emrp.getFirst().getEmployeeName()); + } return "topmenu"; } } \ No newline at end of file diff --git a/src/main/resources/templates/topmenu.html b/src/main/resources/templates/topmenu.html index fa101d6..6371da6 100644 --- a/src/main/resources/templates/topmenu.html +++ b/src/main/resources/templates/topmenu.html @@ -1,6 +1,6 @@ - - + + トップメニュー @@ -17,7 +17,7 @@
- テストユーザー(一般) +

@@ -61,15 +61,17 @@
+ -
+ -

新規図書登録

+

新規図書登録

図書の登録申請を
行います。

+
@@ -103,7 +105,12 @@ 初期パスワードを
変更します。

+ + + \ No newline at end of file