3 Commits

6 changed files with 88 additions and 77 deletions

View File

@@ -47,15 +47,13 @@ public class BookInsertController {
// 初期表示: 空のformを渡す(th:fieldの初期値が空になる) // 初期表示: 空のformを渡す(th:fieldの初期値が空になる)
// 確認画面から戻る: POSTされた入力中の値がformに入ったまま入力画面へ // 確認画面から戻る: POSTされた入力中の値がformに入ったまま入力画面へ
//入力内容確認してOKであれば確認画面へ
@PostMapping("/bookInsertConfirm") @PostMapping("/bookInsertConfirm")
public String bookInsertConfirm(@Validated BookInsert bookInsert,BindingResult result,Model model) { public String bookInsertConfirm(@Validated BookInsert bookInsert,BindingResult result,Model model) {
if(result.hasErrors()) { if(result.hasErrors()) {
model.addAttribute("nextBookManageId",bookInsertService.createBookManageId()); model.addAttribute("nextBookManageId",bookInsertService.createBookManageId());
model.addAttribute("categoryList",categoryRepository.findAll()); model.addAttribute("categoryList",categoryRepository.findAll());
if(bookInsert.getBookCategoryId() != null) { //nullじゃなかったら if(bookInsert.getBookCategoryId() != null) { //nullじゃなかったら
model.addAttribute("subCategoryList", model.addAttribute("subCategoryList",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
//そのカテゴリに属するサブカテゴリを持ってくる //そのカテゴリに属するサブカテゴリを持ってくる
} else{ } else{
model.addAttribute("subCategoryList",subCategoryRepository.findAll()); model.addAttribute("subCategoryList",subCategoryRepository.findAll());
@@ -70,18 +68,27 @@ public class BookInsertController {
return "bookInsertConfirm"; return "bookInsertConfirm";
} }
//確認画面から「もどる」ボタンを押したら入力画面に戻る
@PostMapping("/bookInsert")
public String bookInsertBack(BookInsert bookInsert,Model model) {
model.addAttribute("nextBookManageId",bookInsertService.createBookManageId());
model.addAttribute("categoryList",categoryRepository.findAll());
if(bookInsert.getBookCategoryId() !=null) {
model.addAttribute("subCategoryList",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
} else{
model.addAttribute("subCategoryList",subCategoryRepository.findAll());
}
model.addAttribute("locationList",storageLocationRepository.findAll());
model.addAttribute("bookInsert",bookInsert);
return "bookInsert";
}
@PostMapping("/bookInsert/category") @PostMapping("/bookInsert/category")
public String changeCategory(BookInsert bookInsert,Model model) { public String changeCategory(BookInsert bookInsert,Model model) {
//カテゴリプルダウンに表示するデータを取得 //カテゴリプルダウンに表示するデータを取得
model.addAttribute("nextBookManageId",bookInsertService.createBookManageId()); model.addAttribute("nextBookManageId",bookInsertService.createBookManageId());
model.addAttribute("categoryList",categoryRepository.findAll()); model.addAttribute("categoryList",categoryRepository.findAll());
if (bookInsert.getBookCategoryId() != null) { //nullじゃなかったら model.addAttribute("subCategoryList",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
model.addAttribute("subCategoryList",
subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
//そのカテゴリに属するサブカテゴリを持ってくる
} else {
model.addAttribute("subCategoryList", subCategoryRepository.findAll());
}
model.addAttribute("locationList",storageLocationRepository.findAll()); model.addAttribute("locationList",storageLocationRepository.findAll());
model.addAttribute("bookInsert", bookInsert); model.addAttribute("bookInsert", bookInsert);
@@ -90,7 +97,13 @@ public class BookInsertController {
} }
//画面で選択したカテゴリbookInsert.getBookCategoryId()に選択した結果をいれる //画面で選択したカテゴリbookInsert.getBookCategoryId()に選択した結果をいれる
//subCategoryRepository.findBookCategory_BookCategoryId(bookInsert.getBookCategoryId(1))); //subCategoryRepository.findBookCategory_BookCategoryId(bookInsert.getBookCategoryId(1)));
//「カテゴリIDが1のサブカテゴリを取ってくる」 //「カテゴリIDが1のサブカテゴリを取ってくる」
//model.addAttribute("subCategoryList",取得結果) //model.addAttribute("subCategoryList",取得結果)

View File

@@ -74,7 +74,7 @@ public class LoginController {
AccountEntity accountEntity = loginService.login(loginForm); AccountEntity accountEntity = loginService.login(loginForm);
if (accountEntity == null) { if (accountEntity == null) {
model.addAttribute("loginError", model.addAttribute("loginError",
"ログインIDまたはパスワードが正しくありません"); "社員IDまたはパスワードが正しくありません");
return "login"; return "login";
} }

View File

@@ -1,7 +1,5 @@
package com.example.demo.repository; package com.example.demo.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@@ -10,6 +8,4 @@ import com.example.demo.entity.BookLend;
@Repository @Repository
public interface BookLendRepository extends JpaRepository<BookLend, Integer> { public interface BookLendRepository extends JpaRepository<BookLend, Integer> {
List<BookLend> findBybookStatus(Integer bookStatus);
} }

View File

@@ -15,7 +15,7 @@ public class BookLendService {
private BookLendRepository bookLendRepository; private BookLendRepository bookLendRepository;
public List<BookLend> findAll() { public List<BookLend> findAll() {
return bookLendRepository.findBybookStatus(1); return bookLendRepository.findAll();
} }
} }

View File

@@ -4,6 +4,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>ログイン</title> <title>ログイン</title>
</head> </head>
<body> <body>
@@ -16,7 +17,7 @@
<form th:action="@{/login}" th:object="${loginForm}" method="post"> <form th:action="@{/login}" th:object="${loginForm}" method="post">
<div class="form-group"> <div class="form-group">
<label for="employeeId">社員ID</label> <label for="employeeId">社員ID</label>
<input id="employeeId" type="text" th:field="*{employeeId}"> <input id="employeeId" type="text" th:field="*{employeeId}"pattern="^[0-9]+$"title="数値以外は入力しないでください">
<p class="field-error" th:errors="*{employeeId}"></p> <p class="field-error" th:errors="*{employeeId}"></p>
</div> </div>

View File

@@ -97,6 +97,7 @@
</a> </a>
<hr> <hr>
</th>
<a class="card" href="/passwordChange"> <a class="card" href="/passwordChange">
<h3>パスワード変更</h3> <h3>パスワード変更</h3>
@@ -105,7 +106,7 @@
初期パスワードを<br> 変更します。 初期パスワードを<br> 変更します。
</p> </p>
</a> </a>
</th>
</body> </body>