3 Commits

3 changed files with 66 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
package com.example.demo.app.presentation.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class ErrorController {
@GetMapping("/error")
public String showError() {
return "error";
}
}

View File

@@ -0,0 +1,22 @@
package com.example.demo.exception;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
public String handleException(
Exception e,
Model model) {
model.addAttribute(
"errorMessage",
"システムエラーが発生しました。"
+ "初めからやり直してください。");
return "error";
}
}

View File

@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1">
<title>エラー</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
</head>
<body>
<div th:replace="~{header :: header}">
</div>
<div class="container text-center mt-5">
<h2 class="text-danger">
エラーが発生しました
</h2>
<p th:text="${errorMessage}"></p>
<a class="btn btn-primary" th:href="@{/login}">
ログイン画面へ
</a>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>