From 0b9eff82c54b800c247d0c2ca3405af4b742256b Mon Sep 17 00:00:00 2001 From: kkazuya Date: Tue, 29 Sep 2026 13:06:31 +0900 Subject: [PATCH] =?UTF-8?q?[EDIT]=20=E4=BA=8C=E6=AC=A1=E5=AE=9F=E8=A3=85?= =?UTF-8?q?=E3=81=AB=E4=BC=B4=E3=81=86=E5=AE=9A=E6=95=B0=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E3=81=A8=E3=80=81AOP=E3=81=AE=E3=82=AF=E3=83=A9?= =?UTF-8?q?=E3=82=B9=E3=82=82=E5=AE=9A=E6=95=B0=E3=82=AF=E3=83=A9=E3=82=B9?= =?UTF-8?q?=E3=82=92=E5=8F=82=E7=85=A7=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E7=B7=A8=E9=9B=86=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/aop/aspect/SessionCheckAspect.java | 3 ++- .../demo/aop/handler/GlobalExceptionHandler.java | 14 ++++++++------ .../presentation/controller/GoalController.java | 2 +- .../pageproperty/PageReturnAttributeKeyword.java | 3 ++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/example/demo/aop/aspect/SessionCheckAspect.java b/src/main/java/com/example/demo/aop/aspect/SessionCheckAspect.java index 3043c98..37faa6d 100644 --- a/src/main/java/com/example/demo/aop/aspect/SessionCheckAspect.java +++ b/src/main/java/com/example/demo/aop/aspect/SessionCheckAspect.java @@ -10,6 +10,7 @@ import org.aspectj.lang.annotation.Pointcut; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import com.example.demo.app.presentation.controller.pageproperty.SessionKeyword; import com.example.demo.exception.NoSessionException; @@ -32,7 +33,7 @@ public class SessionCheckAspect { public void checkSession() { HttpSession session = request.getSession(false); - if (session == null || session.getAttribute("loginUser") == null) { + if (session == null || session.getAttribute(SessionKeyword.LOGIN_USER) == null) { throw new NoSessionException("不正なログインです"); } diff --git a/src/main/java/com/example/demo/aop/handler/GlobalExceptionHandler.java b/src/main/java/com/example/demo/aop/handler/GlobalExceptionHandler.java index 2814100..83554ed 100644 --- a/src/main/java/com/example/demo/aop/handler/GlobalExceptionHandler.java +++ b/src/main/java/com/example/demo/aop/handler/GlobalExceptionHandler.java @@ -12,6 +12,8 @@ import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; +import com.example.demo.app.presentation.controller.pageproperty.PageReturnAttributeKeyword; +import com.example.demo.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword; import com.example.demo.exception.NoSessionException; @ControllerAdvice @@ -30,18 +32,18 @@ public class GlobalExceptionHandler { LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e); model.addAttribute( - "errorMessage", + PageReturnAttributeKeyword.ERROR_MESSAGE, "システムエラーが発生しました。" + "初めからやり直してください。"); - return "redirect:/login"; + return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.LOGIN; } @ExceptionHandler(HttpRequestMethodNotSupportedException.class) public String handleBadRequestException(Model model, Exception e, HttpSession session) { - model.addAttribute("error", SEVERE_ERROR_MESSAGE_BAD_REQUEST); - model.addAttribute("status", HttpStatus.BAD_REQUEST.value()); + model.addAttribute(PageReturnAttributeKeyword.ERROR, SEVERE_ERROR_MESSAGE_BAD_REQUEST); + model.addAttribute(PageReturnAttributeKeyword.STATUS, HttpStatus.BAD_REQUEST.value()); e.printStackTrace(); @@ -50,7 +52,7 @@ public class GlobalExceptionHandler { System.out.println("session invalidated"); session.invalidate(); - return "error"; + return TransitionTargetPageNameKeyword.ERROR_HTML; } @ExceptionHandler(Exception.class) @@ -60,6 +62,6 @@ public class GlobalExceptionHandler { System.out.println("session invalidated exception"); session.invalidate(); - return "error"; + return TransitionTargetPageNameKeyword.ERROR_HTML; } } diff --git a/src/main/java/com/example/demo/app/presentation/controller/GoalController.java b/src/main/java/com/example/demo/app/presentation/controller/GoalController.java index cb7ee49..2ced072 100644 --- a/src/main/java/com/example/demo/app/presentation/controller/GoalController.java +++ b/src/main/java/com/example/demo/app/presentation/controller/GoalController.java @@ -275,7 +275,7 @@ public class GoalController { int currentAmount = goalService.getCurrentAmount(userId); - model.addAttribute("currentAmount", currentAmount); + model.addAttribute(PageReturnAttributeKeyword.CURRENT_AMOUNT, currentAmount); return TransitionTargetPageNameKeyword.GOAL_CREATE_HTML; } diff --git a/src/main/java/com/example/demo/app/presentation/controller/pageproperty/PageReturnAttributeKeyword.java b/src/main/java/com/example/demo/app/presentation/controller/pageproperty/PageReturnAttributeKeyword.java index 3b0a32a..1b89364 100644 --- a/src/main/java/com/example/demo/app/presentation/controller/pageproperty/PageReturnAttributeKeyword.java +++ b/src/main/java/com/example/demo/app/presentation/controller/pageproperty/PageReturnAttributeKeyword.java @@ -4,7 +4,8 @@ public class PageReturnAttributeKeyword { public static final String ERROR_MESSAGE = "errorMessage"; public static final String MESSAGE = "message"; - + public static final String ERROR = "error"; + public static final String STATUS = "status"; public static final String QUESTION_LIST = "questionList"; public static final String USER_FORM = "userForm";