Compare commits
4 Commits
y-kumaki
...
d7e12cc4f1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7e12cc4f1 | ||
|
|
772d0ef594 | ||
|
|
14e060588c | ||
|
|
67a8576a59 |
@@ -6,23 +6,55 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import com.example.demo.entity.Book;
|
||||
import com.example.demo.form.BookSearchForm;
|
||||
import com.example.demo.service.BookServiceImpl;
|
||||
|
||||
@Controller
|
||||
public class BookController {
|
||||
@Autowired
|
||||
private BookServiceImpl bookService;
|
||||
|
||||
|
||||
/* 一覧表示 */
|
||||
@GetMapping("/book")
|
||||
public String book(Model model) {
|
||||
|
||||
|
||||
List<Book> aaa = bookService.findAll();
|
||||
|
||||
|
||||
// DBから取得したデータをHTMLで扱えるようにする
|
||||
model.addAttribute("book",bookService.findAll());
|
||||
model.addAttribute("book", bookService.findAll());
|
||||
|
||||
model.addAttribute("bookSearchForm", new BookSearchForm());
|
||||
|
||||
return "book";
|
||||
}
|
||||
|
||||
/* 検索処理 */
|
||||
@GetMapping("/searchBooks")
|
||||
public String searchBooks(@ModelAttribute BookSearchForm bookSearchForm,
|
||||
Model model) {
|
||||
|
||||
model.addAttribute("book", bookService.findBooks(bookSearchForm.getKeyword()));
|
||||
|
||||
model.addAttribute("bookSearchForm", bookSearchForm);
|
||||
|
||||
return "book";
|
||||
|
||||
}
|
||||
|
||||
/* クリア処理 */
|
||||
@PostMapping("/clearBookList")
|
||||
public String clearBookList(Model model) {
|
||||
|
||||
model.addAttribute("book", bookService.findAll());
|
||||
|
||||
model.addAttribute("bookSearchForm", new BookSearchForm());
|
||||
|
||||
// 一覧表示画面に戻る
|
||||
return "/book";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.example.demo.form;
|
||||
|
||||
public class BookForm {
|
||||
|
||||
}
|
||||
10
src/main/java/com/example/demo/form/BookSearchForm.java
Normal file
10
src/main/java/com/example/demo/form/BookSearchForm.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.example.demo.form;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class BookSearchForm {
|
||||
private String keyword;
|
||||
}
|
||||
@@ -1,10 +1,20 @@
|
||||
package com.example.demo.repository;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import com.example.demo.entity.Book;
|
||||
|
||||
public interface BookRepository extends JpaRepository<Book, Integer>{
|
||||
|
||||
@Query("""
|
||||
SELECT b FROM Book b
|
||||
WHERE b.title LIKE %:keyword%
|
||||
OR b.publisher LIKE %:keyword%
|
||||
OR b.author LIKE %:keyword%
|
||||
""")
|
||||
List<Book> searchBooks(@Param("keyword")String keyword);
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.entity.Book;
|
||||
|
||||
public interface BookService {
|
||||
String booklist(Book book);
|
||||
|
||||
List<java.awt.print.Book> findAll();
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -10,26 +9,17 @@ import com.example.demo.entity.Book;
|
||||
import com.example.demo.repository.BookRepository;
|
||||
|
||||
@Service
|
||||
public class BookServiceImpl{
|
||||
|
||||
public class BookServiceImpl {
|
||||
|
||||
@Autowired
|
||||
private BookRepository bookRepository;
|
||||
|
||||
// @Override
|
||||
// public String booklist(com.example.demo.entity.Book book) {
|
||||
// Book booklist = new Book();
|
||||
// booklist.setBookId(book.getBookId());
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
public List<Book> findAll() {
|
||||
return bookRepository.findAll();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<Book> findBooks(String keyword){
|
||||
return bookRepository.searchBooks(keyword);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,12 +12,33 @@
|
||||
<h1>社内図書一覧</h1>
|
||||
<div class="float-end">
|
||||
</div>
|
||||
|
||||
<form class="input-group" th:action="@{/searchBooks}" th:object="${bookSearchForm}" method="get">
|
||||
|
||||
<input type="text" th:field="*{keyword}" class="form-control" placeholder="キーワードを入力">
|
||||
|
||||
<button class="btn btn-outline-success" type="submit">
|
||||
検索
|
||||
</button>
|
||||
|
||||
</form>
|
||||
|
||||
<form method="post" th:action="@{/clearBookList}">
|
||||
<button class="button button-secondary" type="submit">
|
||||
クリア
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p>※「タイトル」「出版社」「著者名」で検索</p>
|
||||
|
||||
|
||||
|
||||
<form method="get" action="bookLend">
|
||||
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>図書ID</th>
|
||||
<th>図書管理ID</th>
|
||||
<th>ISBN</th>
|
||||
<th>タイトル</th>
|
||||
<th>著者名</th>
|
||||
@@ -30,14 +51,14 @@
|
||||
<th>登録日時</th>
|
||||
<th>更新日時</th>
|
||||
<th>寄贈者</th>
|
||||
<th>貸出状態??</th>
|
||||
<th>操作??</th>
|
||||
<th>貸出状態</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr th:each="book : ${book}">
|
||||
|
||||
<tr th:each="book : ${book}" th:if="${book.bookManageId != null}">
|
||||
|
||||
<td th:text="*{book.bookManageId}"></td>
|
||||
<td th:text="*{book.isbn}"></td>
|
||||
<td th:text="*{book.title}"></td>
|
||||
@@ -47,52 +68,47 @@
|
||||
<td th:text="*{book.bookSubcategory.bookCategory.bookCategoryName}"></td>
|
||||
<td th:text="*{book.bookSubcategory.bookSubcategoryName}"></td>
|
||||
<td th:text="*{book.storageLocation.locationName}"></td>
|
||||
<td th:text="*{book.condition}"></td>
|
||||
<td th:text="*{book.condition == 0 ? '分からない':
|
||||
book.condition == 1 ? '新品':
|
||||
book.condition == 2 ? '良好':
|
||||
book.condition == 3 ? '使用感あり':
|
||||
book.condition == 4 ? '痛みあり':
|
||||
'不明'}">
|
||||
</td>
|
||||
<td th:text="*{book.createdAt}"></td>
|
||||
<td th:text="*{book.updatedAt}"></td>
|
||||
<td th:text="*{book.employee != null ? book.employee.employeeId : '-'}"></td>
|
||||
<td th:text="*{book.bookLends != null ? book.bookLends.bookStatus : '-'}"></td>
|
||||
|
||||
|
||||
|
||||
<td th:text="*{book.employee != null ? book.employee.employeeName : '-'}"></td>
|
||||
<td
|
||||
th:text="*{book.bookLends != null ? (book.bookLends.bookStatus == 0 ? '貸出可': '貸出不可') : '貸出可'}">
|
||||
</td>
|
||||
<td>
|
||||
<form method="post" action="/bookLend">
|
||||
<input type="hidden" name="bookManageId" th:value="*{book.bookManageId}">
|
||||
<button type="submit"
|
||||
th:disabled="*{book.bookLends != null && book.bookLends.bookStatus == 1}">
|
||||
貸出
|
||||
</button>
|
||||
</form>
|
||||
<form method="post" action="/updateconfirm">
|
||||
<input type="hidden" name="bookManageId" th:value="*{book.bookManageId}">
|
||||
<button type="submit">更新</button>
|
||||
</form>
|
||||
<form method="get" action="/delete">
|
||||
<input type="hidden" name="bookManageId" th:value="*{book.bookManageId}">
|
||||
<button type="submit">削除</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr th:if="${#lists.isEmpty(book)}">
|
||||
<td colspan="15">
|
||||
該当する図書がありません
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<button type="submit" class="btn-login">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
||||
stroke-linejoin="round">
|
||||
<path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4" />
|
||||
<polyline points="10 17 15 12 10 7" />
|
||||
<line x1="15" y1="12" x2="3" y2="12" />
|
||||
</svg>
|
||||
貸出
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<button type="submit" class="btn-login">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
||||
stroke-linejoin="round">
|
||||
<path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4" />
|
||||
<polyline points="10 17 15 12 10 7" />
|
||||
<line x1="15" y1="12" x2="3" y2="12" />
|
||||
</svg>
|
||||
貸出
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<form method="post" action="update">
|
||||
<button type="submit" class="btn-login">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
||||
stroke-linejoin="round">
|
||||
<path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4" />
|
||||
<polyline points="10 17 15 12 10 7" />
|
||||
<line x1="15" y1="12" x2="3" y2="12" />
|
||||
</svg>
|
||||
更新
|
||||
</button>
|
||||
</form>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user