From 7b70861fd8024bf6f5164495e10345b894200bec Mon Sep 17 00:00:00 2001 From: w-yuki Date: Fri, 25 Sep 2026 16:36:18 +0900 Subject: [PATCH] =?UTF-8?q?[add]=E3=83=97=E3=83=AB=E3=83=80=E3=82=A6?= =?UTF-8?q?=E3=83=B3=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/controller/BookInsertController.java | 15 +++- .../com/example/demo/entity/BookInsert.java | 4 +- .../repository/StorageLocationRepository.java | 9 ++ src/main/resources/templates/bookInsert.html | 84 +++++++++---------- 4 files changed, 64 insertions(+), 48 deletions(-) create mode 100644 src/main/java/com/example/demo/repository/StorageLocationRepository.java diff --git a/src/main/java/com/example/demo/controller/BookInsertController.java b/src/main/java/com/example/demo/controller/BookInsertController.java index 6ed1d7b..c725330 100644 --- a/src/main/java/com/example/demo/controller/BookInsertController.java +++ b/src/main/java/com/example/demo/controller/BookInsertController.java @@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.PostMapping; import com.example.demo.entity.BookInsert; import com.example.demo.repository.BookCategoryRepository; +import com.example.demo.repository.StorageLocationRepository; import com.example.demo.repository.SubCategoryRepository; import com.example.demo.service.BookInsertService; @@ -21,13 +22,18 @@ private BookInsertService bookInsertService; @Autowired private BookCategoryRepository categoryRepository; + @Autowired private SubCategoryRepository subCategoryRepository; +@Autowired +private StorageLocationRepository storageLocationRepository; + @GetMapping("/bookInsert") public String bookInsert(Model model) { model.addAttribute("categoryList",categoryRepository.findAll()); model.addAttribute("subCategoryList",subCategoryRepository.findAll()); + model.addAttribute("locationList",storageLocationRepository.findAll()); model.addAttribute("bookInsert",new BookInsert()); return "bookInsert"; } @@ -37,6 +43,7 @@ private SubCategoryRepository subCategoryRepository; // 確認画面から戻る: POSTされた入力中の値がformに入ったまま入力画面へ @PostMapping("/bookInsertConfirm") public String bookInsertConfirm(BookInsert bookInsert,Model model) { + System.out.println(bookInsert); bookInsertService.save(bookInsert); model.addAttribute("bookInsert",bookInsert); return "bookInsertConfirm"; @@ -46,6 +53,7 @@ private SubCategoryRepository subCategoryRepository; public String bookInsertBack(BookInsert bookInsert,Model model) { model.addAttribute("categoryList",categoryRepository.findAll()); model.addAttribute("subCategoryList",new ArrayList<>()); + model.addAttribute("locationList",storageLocationRepository.findAll()); model.addAttribute("bookInsert",bookInsert); return "bookInsert"; } @@ -56,16 +64,21 @@ private SubCategoryRepository subCategoryRepository; 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()) + //画面で選択したカテゴリbookInsert.getBookCategoryId()に選択した結果をいれる + //subCategoryRepository.findBookCategory_BookCategoryId(bookInsert.getBookCategoryId(1))); + //「カテゴリIDが1のサブカテゴリを取ってくる」 + //model.addAttribute("subCategoryList",取得結果) diff --git a/src/main/java/com/example/demo/entity/BookInsert.java b/src/main/java/com/example/demo/entity/BookInsert.java index ffe074a..9305b62 100644 --- a/src/main/java/com/example/demo/entity/BookInsert.java +++ b/src/main/java/com/example/demo/entity/BookInsert.java @@ -40,7 +40,7 @@ public class BookInsert { private String publisher; @Column(name = "publication_date") - private String publicationDate; + private LocalDate publicationDate; @Column(name = "location_id") private Integer location; @@ -66,7 +66,7 @@ public class BookInsert { @Column(name = "book_approval") private Integer bookApproval; - @Transient + @Transient //DB保存無効 private Integer bookCategoryId; diff --git a/src/main/java/com/example/demo/repository/StorageLocationRepository.java b/src/main/java/com/example/demo/repository/StorageLocationRepository.java new file mode 100644 index 0000000..861a62a --- /dev/null +++ b/src/main/java/com/example/demo/repository/StorageLocationRepository.java @@ -0,0 +1,9 @@ +package com.example.demo.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.example.demo.entity.StorageLocation; + +public interface StorageLocationRepository extends JpaRepository { + +} \ No newline at end of file diff --git a/src/main/resources/templates/bookInsert.html b/src/main/resources/templates/bookInsert.html index 467e577..059917e 100644 --- a/src/main/resources/templates/bookInsert.html +++ b/src/main/resources/templates/bookInsert.html @@ -8,17 +8,12 @@

新規図書登録入力

- -


- +

新しく図書を登録します。必要事項jを入力し、「登録」ボタンを押してください

+ ※は必須項目です +

-
- -




-
+


-
- +
+

-
+


+
- + +

-
+


- -
- + +
+

-
- -

- -
- -

- -
- +

+ +
+ +

+ +
+ +


@@ -103,7 +97,7 @@ --> - +