完成 ver1
This commit is contained in:
@@ -66,7 +66,6 @@ public class SelectBookController {
|
|||||||
//書籍一覧画面へ遷移
|
//書籍一覧画面へ遷移
|
||||||
return "bookList";
|
return "bookList";
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//httpSessionを破棄
|
//httpSessionを破棄
|
||||||
httpsession.invalidate();
|
httpsession.invalidate();
|
||||||
@@ -82,21 +81,30 @@ public class SelectBookController {
|
|||||||
// ② 検索ボタン押下時の処理
|
// ② 検索ボタン押下時の処理
|
||||||
|
|
||||||
@RequestMapping(value = "/selectBook", method = RequestMethod.POST)
|
@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 {
|
try {
|
||||||
// LoginUser loginUser = (LoginUser) httpsession.getAttribute("loginUser");
|
|
||||||
//
|
System.out.println("検索処理が実行されました");
|
||||||
// //ログイン情報が存在しない場合はログイン画面へ
|
// HTMLから受け取った書籍名を確認する
|
||||||
// if(loginUser == null) {
|
System.out.println("書籍名:" + searchConditionBookForm.getNmBook());
|
||||||
// return "/login";
|
// Serviceを呼び出して検索する
|
||||||
// }
|
|
||||||
//
|
|
||||||
List<Book_collectionEntity> books = returnService.searchByWithLike(searchConditionBookForm);
|
List<Book_collectionEntity> books = returnService.searchByWithLike(searchConditionBookForm);
|
||||||
|
// 検索結果の件数を確認する
|
||||||
|
System.out.println("検索結果;" + books.size() + "件");
|
||||||
|
// 検索結果をModelに登録する
|
||||||
model.addAttribute("books", books);
|
model.addAttribute("books", books);
|
||||||
// boolean isAdmin = loginUser.isAdminUser();
|
// 書籍一覧画面へ遷移
|
||||||
// model.addAttribute("isAdmin" , isAdmin);
|
|
||||||
return "bookList";
|
return "bookList";
|
||||||
|
|
||||||
|
// // 検索結果をModelに登録する
|
||||||
|
// model.addAttribute("books", books);
|
||||||
|
// // 書籍一覧画面へ遷移
|
||||||
|
// return "bookList";
|
||||||
|
|
||||||
|
// model.addAttribute("isAdmin" , isAdmin);
|
||||||
|
// return "bookList";
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//httpSessionを破棄
|
//httpSessionを破棄
|
||||||
httpsession.invalidate();
|
httpsession.invalidate();
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import com.example.demo.entity.Book_collectionEntity;
|
|||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface Book_CollectionRepository extends JpaRepository<Book_collectionEntity, Integer> {
|
public interface Book_CollectionRepository extends JpaRepository<Book_collectionEntity, Integer> {
|
||||||
|
//JpaRepositoruを継承することで基本的なDB操作が使用できる
|
||||||
|
//Book_collctionEntity:操作するEntity
|
||||||
|
//Integer: Entity の主キーの方
|
||||||
List<Book_collectionEntity> findByFlgLending(Character flgLending);
|
List<Book_collectionEntity> findByFlgLending(Character flgLending);
|
||||||
|
|
||||||
@Query("""
|
@Query("""
|
||||||
@@ -21,7 +24,17 @@ public interface Book_CollectionRepository extends JpaRepository<Book_collection
|
|||||||
AND (:noteText = '' OR b.noteText LIKE CONCAT('%',:noteText,'%'))
|
AND (:noteText = '' OR b.noteText LIKE CONCAT('%',:noteText,'%'))
|
||||||
ORDER BY b.idBook
|
ORDER BY b.idBook
|
||||||
""")
|
""")
|
||||||
|
//上から:貸出フラグが'0'の書籍だけを取得する
|
||||||
|
//書籍名が空欄なら絞り込まない、入力されてるなら部分一致検索する
|
||||||
|
//出版社が...
|
||||||
|
//特記事項が...
|
||||||
|
//蔵書IDの昇順で並べる
|
||||||
|
|
||||||
|
|
||||||
|
//書籍名・出版社・特記事項を条件に書籍を検索するメソッド
|
||||||
|
//検索結果はBook_collectionEntityのListで返す
|
||||||
List<Book_collectionEntity> searchBooks(
|
List<Book_collectionEntity> searchBooks(
|
||||||
|
//入力された書籍名をJPQLの:nmBookに返す
|
||||||
@Param("nmBook") String nmBook,
|
@Param("nmBook") String nmBook,
|
||||||
@Param("pubLisher") String pubLisher,
|
@Param("pubLisher") String pubLisher,
|
||||||
@Param("noteText") String noteText);
|
@Param("noteText") String noteText);
|
||||||
|
|||||||
@@ -6,41 +6,53 @@
|
|||||||
<title>書籍一覧・検索</title>
|
<title>書籍一覧・検索</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
<!--画面に表示する内容-->
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<!--ログアウトボタン-->
|
<!--ログアウトボタン-->
|
||||||
<a href="@{/logout}">ログアウト</a>
|
<a href="@{/logout}">ログアウト</a>
|
||||||
|
|
||||||
<h2>書籍一覧・検索</h2>
|
<h2>書籍一覧・検索</h2>
|
||||||
|
<!-- 検索条件をControllerの/selectBookへPOST送信-->
|
||||||
|
<!--bookSearchFormはControllerから渡されるForm-->
|
||||||
<!--Controllerと@{/selectBook}合わせる-->
|
<!--Controllerと@{/selectBook}合わせる-->
|
||||||
<form th:action="@{/selectBook}" th:object="${bookSearchForm}" method="post">
|
<form th:action="@{/selectBook}" th:object="${bookSearchForm}" method="post">
|
||||||
|
|
||||||
|
<!-- 検索条件を入力するためのテーブル-->
|
||||||
<table>
|
<table>
|
||||||
<!-- 書籍名-->
|
<!-- 書籍名-->
|
||||||
<tr>
|
<tr>
|
||||||
<th class="header">書籍名</th>
|
<th class="header">書籍名</th>
|
||||||
|
<!-- FormのnmBookフィールドと関連付ける-->
|
||||||
<td><input type="text" th:field="*{nmBook}" /></td>
|
<td><input type="text" th:field="*{nmBook}" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
<!-- 出版社-->
|
<!-- 出版社-->
|
||||||
<tr>
|
<tr>
|
||||||
<th class="header">出版社</th>
|
<th class="header">出版社</th>
|
||||||
|
<!-- FormのpubLisherフィールドと関連付ける-->
|
||||||
<td><input type="text" th:field="*{pubLisher}"></td>
|
<td><input type="text" th:field="*{pubLisher}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<!-- 特記事項-->
|
<!-- 特記事項-->
|
||||||
<tr>
|
<tr>
|
||||||
<th class="header">特記事項</th>
|
<th class="header">特記事項</th>
|
||||||
|
<!-- FormのnoteTextフィールドと関連付ける-->
|
||||||
<td><input type="text" th:field="*{noteText}"></td>
|
<td><input type="text" th:field="*{noteText}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
<!-- 検索ボタン-->
|
<!-- 検索ボタン-->
|
||||||
<button type="submit">検索</button>
|
<button type="submit">検索</button>
|
||||||
</form>
|
</form>
|
||||||
<!-- メニュー画面へ戻る-->
|
<!-- メニュー画面へ戻るリンク-->
|
||||||
<a th:href="@{/menu}">メニューに戻る </a>
|
<a th:href="@{/menu}">メニューに戻る </a>
|
||||||
<h3>検索結果</h3>
|
<h3>検索結果</h3>
|
||||||
<!-- 検索結果一覧-->
|
|
||||||
|
<!--検索結果を表示するテーブル-->
|
||||||
<table border="1">
|
<table border="1">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th>書籍ID</th>
|
||||||
<th>ISBN</th>
|
<th>ISBN</th>
|
||||||
<th>書籍名</th>
|
<th>書籍名</th>
|
||||||
<th>書籍名よみ</th>
|
<th>書籍名よみ</th>
|
||||||
@@ -49,10 +61,14 @@
|
|||||||
<th style="width: 150px;">操作</th>
|
<th style="width: 150px;">操作</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<!--検索結果を表示-->
|
<!--検索結果を表示-->
|
||||||
<tbody>
|
<tbody>
|
||||||
<!-- booksのデータを1件ずつ取り出す-->
|
<!--Controllerから渡されたbooksのデータを1件ずつ取り出す-->
|
||||||
|
<!-- bookには1件分の書籍情報が入る-->
|
||||||
<tr th:each="book : ${books}">
|
<tr th:each="book : ${books}">
|
||||||
|
<!--書籍ID-->
|
||||||
|
<td th:text="${book.idBook}"></td>
|
||||||
<!--ISBN-->
|
<!--ISBN-->
|
||||||
<td th:text="${book.isBn}"></td>
|
<td th:text="${book.isBn}"></td>
|
||||||
<!--書籍名-->
|
<!--書籍名-->
|
||||||
|
|||||||
Reference in New Issue
Block a user