3 Commits

6 changed files with 88 additions and 77 deletions

View File

@@ -18,79 +18,92 @@ import com.example.demo.service.BookInsertService;
@Controller @Controller
public class BookInsertController { public class BookInsertController {
@Autowired @Autowired
private BookInsertService bookInsertService; private BookInsertService bookInsertService;
@Autowired @Autowired
private BookCategoryRepository categoryRepository; private BookCategoryRepository categoryRepository;
@Autowired @Autowired
private SubCategoryRepository subCategoryRepository; private SubCategoryRepository subCategoryRepository;
@Autowired @Autowired
private StorageLocationRepository storageLocationRepository; private StorageLocationRepository storageLocationRepository;
@Autowired @Autowired
private BookInsertRepository bookInsertRepository; private BookInsertRepository bookInsertRepository;
@GetMapping("/bookInsert") @GetMapping("/bookInsert")
public String bookInsert(Model model) { public String bookInsert(Model model) {
model.addAttribute("nextBookManageId", bookInsertService.createBookManageId()); model.addAttribute("nextBookManageId",bookInsertService.createBookManageId());
model.addAttribute("bookInsert", new BookInsert()); model.addAttribute("bookInsert",new BookInsert());
model.addAttribute("categoryList", categoryRepository.findAll()); model.addAttribute("categoryList",categoryRepository.findAll());
model.addAttribute("subCategoryList", subCategoryRepository.findAll()); model.addAttribute("subCategoryList",subCategoryRepository.findAll());
model.addAttribute("locationList", storageLocationRepository.findAll()); model.addAttribute("locationList",storageLocationRepository.findAll());
model.addAttribute("bookInsert", new BookInsert()); model.addAttribute("bookInsert",new BookInsert());
return "bookInsert"; return "bookInsert";
} }
// 初期表示: 空の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",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
model.addAttribute("subCategoryList", //そのカテゴリに属するサブカテゴリを持ってくる
subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId())); } else{
//そのカテゴリに属するサブカテゴリを持ってくる model.addAttribute("subCategoryList",subCategoryRepository.findAll());
} else { }
model.addAttribute("subCategoryList", subCategoryRepository.findAll()); model.addAttribute("locationList",storageLocationRepository.findAll());
} model.addAttribute("bookInsert", bookInsert);
model.addAttribute("locationList",storageLocationRepository.findAll()); return "bookInsert";
model.addAttribute("bookInsert", bookInsert);
return "bookInsert";
} }
bookInsertService.save(bookInsert); bookInsertService.save(bookInsert);
model.addAttribute("bookInsert", bookInsert); model.addAttribute("bookInsert",bookInsert);
return "bookInsertConfirm"; return "bookInsertConfirm";
} }
@PostMapping("/bookInsert/category") //確認画面から「もどる」ボタンを押したら入力画面に戻る
public String changeCategory(BookInsert bookInsert, Model model) { @PostMapping("/bookInsert")
//カテゴリプルダウンに表示するデータを取得 public String bookInsertBack(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じゃなかったら if(bookInsert.getBookCategoryId() !=null) {
model.addAttribute("subCategoryList", model.addAttribute("subCategoryList",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId())); } else{
//そのカテゴリに属するサブカテゴリを持ってくる model.addAttribute("subCategoryList",subCategoryRepository.findAll());
} else { }
model.addAttribute("subCategoryList", subCategoryRepository.findAll()); model.addAttribute("locationList",storageLocationRepository.findAll());
} model.addAttribute("bookInsert",bookInsert);
model.addAttribute("locationList", storageLocationRepository.findAll()); return "bookInsert";
model.addAttribute("bookInsert", bookInsert); }
return "bookInsert"; @PostMapping("/bookInsert/category")
} public String changeCategory(BookInsert bookInsert,Model model) {
//カテゴリプルダウンに表示するデータを取得
model.addAttribute("nextBookManageId",bookInsertService.createBookManageId());
model.addAttribute("categoryList",categoryRepository.findAll());
model.addAttribute("subCategoryList",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
model.addAttribute("locationList",storageLocationRepository.findAll());
model.addAttribute("bookInsert", bookInsert);
return "bookInsert";
}
} }
//画面で選択したカテゴリbookInsert.getBookCategoryId()に選択した結果をいれる
//subCategoryRepository.findBookCategory_BookCategoryId(bookInsert.getBookCategoryId(1)));
//「カテゴリIDが1のサブカテゴリを取ってくる」 //画面で選択したカテゴリbookInsert.getBookCategoryId()に選択した結果をいれる
//model.addAttribute("subCategoryList",取得結果) //subCategoryRepository.findBookCategory_BookCategoryId(bookInsert.getBookCategoryId(1)));
//「カテゴリIDが1のサブカテゴリを取ってくる」
//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>