6 Commits

6 changed files with 77 additions and 88 deletions

View File

@@ -17,93 +17,80 @@ import com.example.demo.service.BookInsertService;
@Controller @Controller
public class BookInsertController { public class BookInsertController {
@Autowired
private BookInsertService bookInsertService;
@Autowired @Autowired
private BookCategoryRepository categoryRepository; private BookInsertService bookInsertService;
@Autowired @Autowired
private SubCategoryRepository subCategoryRepository; private BookCategoryRepository categoryRepository;
@Autowired @Autowired
private StorageLocationRepository storageLocationRepository; private SubCategoryRepository subCategoryRepository;
@Autowired @Autowired
private BookInsertRepository bookInsertRepository; private StorageLocationRepository storageLocationRepository;
@GetMapping("/bookInsert") @Autowired
public String bookInsert(Model model) { private BookInsertRepository bookInsertRepository;
model.addAttribute("nextBookManageId",bookInsertService.createBookManageId());
model.addAttribute("bookInsert",new BookInsert()); @GetMapping("/bookInsert")
model.addAttribute("categoryList",categoryRepository.findAll()); public String bookInsert(Model model) {
model.addAttribute("subCategoryList",subCategoryRepository.findAll()); model.addAttribute("nextBookManageId", bookInsertService.createBookManageId());
model.addAttribute("locationList",storageLocationRepository.findAll()); model.addAttribute("bookInsert", new BookInsert());
model.addAttribute("bookInsert",new BookInsert()); model.addAttribute("categoryList", categoryRepository.findAll());
return "bookInsert"; model.addAttribute("subCategoryList", subCategoryRepository.findAll());
} model.addAttribute("locationList", storageLocationRepository.findAll());
model.addAttribute("bookInsert", new BookInsert());
// 初期表示: 空のformを渡す(th:fieldの初期値が空になる) return "bookInsert";
}
// 確認画面から戻る: POSTされた入力中の値がformに入ったまま入力画面へ
@PostMapping("/bookInsertConfirm") // 初期表示: 空のformを渡す(th:fieldの初期値が空になる)
public String bookInsertConfirm(@Validated BookInsert bookInsert,BindingResult result,Model model) {
if(result.hasErrors()) { // 確認画面から戻る: POSTされた入力中の値がformに入ったまま入力画面へ
model.addAttribute("nextBookManageId",bookInsertService.createBookManageId()); //入力内容確認してOKであれば確認画面へ
model.addAttribute("categoryList",categoryRepository.findAll()); @PostMapping("/bookInsertConfirm")
if(bookInsert.getBookCategoryId() != null) { //nullじゃなかったら public String bookInsertConfirm(@Validated BookInsert bookInsert, BindingResult result, Model model) {
model.addAttribute("subCategoryList",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId())); if (result.hasErrors()) {
//そのカテゴリに属するサブカテゴリを持ってくる model.addAttribute("nextBookManageId", bookInsertService.createBookManageId());
} else{ model.addAttribute("categoryList", categoryRepository.findAll());
model.addAttribute("subCategoryList",subCategoryRepository.findAll()); if (bookInsert.getBookCategoryId() != null) { //nullじゃなかったら
} model.addAttribute("subCategoryList",
model.addAttribute("locationList",storageLocationRepository.findAll()); subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
model.addAttribute("bookInsert", bookInsert); //そのカテゴリに属するサブカテゴリを持ってくる
return "bookInsert"; } else {
model.addAttribute("subCategoryList", subCategoryRepository.findAll());
} }
bookInsertService.save(bookInsert); model.addAttribute("locationList",storageLocationRepository.findAll());
model.addAttribute("bookInsert",bookInsert); model.addAttribute("bookInsert", bookInsert);
return "bookInsertConfirm"; return "bookInsert";
}
}
//確認画面から「もどる」ボタンを押したら入力画面に戻る bookInsertService.save(bookInsert);
@PostMapping("/bookInsert") model.addAttribute("bookInsert", bookInsert);
public String bookInsertBack(BookInsert bookInsert,Model model) { return "bookInsertConfirm";
model.addAttribute("nextBookManageId",bookInsertService.createBookManageId()); }
model.addAttribute("categoryList",categoryRepository.findAll());
if(bookInsert.getBookCategoryId() !=null) { @PostMapping("/bookInsert/category")
model.addAttribute("subCategoryList",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId())); public String changeCategory(BookInsert bookInsert, Model model) {
} else{ //カテゴリプルダウンに表示するデータを取得
model.addAttribute("subCategoryList",subCategoryRepository.findAll()); model.addAttribute("nextBookManageId", bookInsertService.createBookManageId());
} model.addAttribute("categoryList", categoryRepository.findAll());
model.addAttribute("locationList",storageLocationRepository.findAll()); if (bookInsert.getBookCategoryId() != null) { //nullじゃなかったら
model.addAttribute("bookInsert",bookInsert); model.addAttribute("subCategoryList",
return "bookInsert"; subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
} //そのカテゴリに属するサブカテゴリを持ってくる
} else {
@PostMapping("/bookInsert/category") model.addAttribute("subCategoryList", subCategoryRepository.findAll());
public String changeCategory(BookInsert bookInsert,Model model) { }
//カテゴリプルダウンに表示するデータを取得 model.addAttribute("locationList", storageLocationRepository.findAll());
model.addAttribute("nextBookManageId",bookInsertService.createBookManageId()); model.addAttribute("bookInsert", bookInsert);
model.addAttribute("categoryList",categoryRepository.findAll());
model.addAttribute("subCategoryList",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId())); return "bookInsert";
model.addAttribute("locationList",storageLocationRepository.findAll()); }
model.addAttribute("bookInsert", bookInsert);
return "bookInsert";
}
} }
//画面で選択したカテゴリ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,5 +1,7 @@
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;
@@ -8,4 +10,6 @@ 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.findAll(); return bookLendRepository.findBybookStatus(1);
} }
} }

View File

@@ -4,7 +4,6 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>ログイン</title> <title>ログイン</title>
</head> </head>
<body> <body>
@@ -17,7 +16,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}"pattern="^[0-9]+$"title="数値以外は入力しないでください"> <input id="employeeId" type="text" th:field="*{employeeId}">
<p class="field-error" th:errors="*{employeeId}"></p> <p class="field-error" th:errors="*{employeeId}"></p>
</div> </div>

View File

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