完成 ver1

This commit is contained in:
2026-10-23 11:26:44 +09:00
parent 0682e588a7
commit c5c786d6d7
3 changed files with 89 additions and 52 deletions

View File

@@ -66,7 +66,6 @@ public class SelectBookController {
//書籍一覧画面へ遷移
return "bookList";
} catch (Exception e) {
//httpSessionを破棄
httpsession.invalidate();
@@ -82,21 +81,30 @@ public class SelectBookController {
// ② 検索ボタン押下時の処理
@RequestMapping(value = "/selectBook", method = RequestMethod.POST)
public String select(@ModelAttribute("bookSearchForm") SearchConditionBookForm searchConditionBookForm, Model model) {
public String select(@ModelAttribute("bookSearchForm") SearchConditionBookForm searchConditionBookForm,
Model model) {
try {
// LoginUser loginUser = (LoginUser) httpsession.getAttribute("loginUser");
//
// //ログイン情報が存在しない場合はログイン画面へ
// if(loginUser == null) {
// return "/login";
// }
//
System.out.println("検索処理が実行されました");
// HTMLから受け取った書籍名を確認する
System.out.println("書籍名:" + searchConditionBookForm.getNmBook());
// Serviceを呼び出して検索する
List<Book_collectionEntity> books = returnService.searchByWithLike(searchConditionBookForm);
// 検索結果の件数を確認する
System.out.println("検索結果;" + books.size() + "件");
// 検索結果をModelに登録する
model.addAttribute("books", books);
// boolean isAdmin = loginUser.isAdminUser();
// model.addAttribute("isAdmin" , isAdmin);
// 書籍一覧画面へ遷移
return "bookList";
// // 検索結果をModelに登録する
// model.addAttribute("books", books);
// // 書籍一覧画面へ遷移
// return "bookList";
// model.addAttribute("isAdmin" , isAdmin);
// return "bookList";
} catch (Exception e) {
//httpSessionを破棄
httpsession.invalidate();

View File

@@ -11,6 +11,9 @@ import com.example.demo.entity.Book_collectionEntity;
@Repository
public interface Book_CollectionRepository extends JpaRepository<Book_collectionEntity, Integer> {
//JpaRepositoruを継承することで基本的なDB操作が使用できる
//Book_collctionEntity:操作するEntity
//Integer: Entity の主キーの方
List<Book_collectionEntity> findByFlgLending(Character flgLending);
@Query("""
@@ -21,7 +24,17 @@ public interface Book_CollectionRepository extends JpaRepository<Book_collection
AND (:noteText = '' OR b.noteText LIKE CONCAT('%',:noteText,'%'))
ORDER BY b.idBook
""")
//上から:貸出フラグが'0'の書籍だけを取得する
//書籍名が空欄なら絞り込まない、入力されてるなら部分一致検索する
//出版社が...
//特記事項が...
//蔵書IDの昇順で並べる
//書籍名・出版社・特記事項を条件に書籍を検索するメソッド
//検索結果はBook_collectionEntityのListで返す
List<Book_collectionEntity> searchBooks(
//入力された書籍名をJPQLの:nmBookに返す
@Param("nmBook") String nmBook,
@Param("pubLisher") String pubLisher,
@Param("noteText") String noteText);

View File

@@ -6,41 +6,53 @@
<title>書籍一覧・検索</title>
</head>
<!--画面に表示する内容-->
<body>
<!--ログアウトボタン-->
<a href="@{/logout}">ログアウト</a>
<h2>書籍一覧・検索</h2>
<!-- 検索条件をControllerの/selectBookへPOST送信-->
<!--bookSearchFormはControllerから渡されるForm-->
<!--Controllerと@{/selectBook}合わせる-->
<form th:action="@{/selectBook}" th:object="${bookSearchForm}" method="post">
<!-- 検索条件を入力するためのテーブル-->
<table>
<!-- 書籍名-->
<tr>
<th class="header">書籍名</th>
<!-- FormのnmBookフィールドと関連付ける-->
<td><input type="text" th:field="*{nmBook}" /></td>
</tr>
<!-- 出版社-->
<tr>
<th class="header">出版社</th>
<!-- FormのpubLisherフィールドと関連付ける-->
<td><input type="text" th:field="*{pubLisher}"></td>
</tr>
<!-- 特記事項-->
<tr>
<th class="header">特記事項</th>
<!-- FormのnoteTextフィールドと関連付ける-->
<td><input type="text" th:field="*{noteText}"></td>
</tr>
</table>
<!-- 検索ボタン-->
<button type="submit">検索</button>
</form>
<!-- メニュー画面へ戻る-->
<!-- メニュー画面へ戻るリンク-->
<a th:href="@{/menu}">メニューに戻る </a>
<h3>検索結果</h3>
<!-- 検索結果一覧-->
<!--検索結果を表示するテーブル-->
<table border="1">
<thead>
<tr>
<th>書籍ID</th>
<th>ISBN</th>
<th>書籍名</th>
<th>書籍名よみ</th>
@@ -49,10 +61,14 @@
<th style="width: 150px;">操作</th>
</tr>
</thead>
<!--検索結果を表示-->
<tbody>
<!-- booksのデータを1件ずつ取り出す-->
<!--Controllerから渡されたbooksのデータを1件ずつ取り出す-->
<!-- bookには1件分の書籍情報が入る-->
<tr th:each="book : ${books}">
<!--書籍ID-->
<td th:text="${book.idBook}"></td>
<!--ISBN-->
<td th:text="${book.isBn}"></td>
<!--書籍名-->