[edit] 図書一覧表示のエラー箇所を修正しました

This commit is contained in:
s-tajihi
2026-09-24 12:52:54 +09:00
parent ab48f30b6e
commit a6a42295c4
6 changed files with 90 additions and 28 deletions

View File

@@ -1,13 +1,21 @@
package com.example.demo.controller; package com.example.demo.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import com.example.demo.service.BookServiceImpl;
@Controller @Controller
public class BookController { public class BookController {
@Autowired
private BookServiceImpl bookService;
@GetMapping("/book") @GetMapping("/book")
public String book(Model model) { public String book(Model model) {
// DBから取得したデータをHTMLで扱えるようにする
model.addAttribute("book",bookService.findAll()); model.addAttribute("book",bookService.findAll());
return "book"; return "book";
} }

View File

@@ -15,7 +15,8 @@ import lombok.Data;
@Data @Data
@Table(name = "book") @Table(name = "book")
public class Book { public class Book {
//貸出処理で使用する図書ID
//図書ID
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "book_Id", nullable = false) @Column(name = "book_Id", nullable = false)
@@ -46,7 +47,7 @@ public class Book {
private Date publicationDate; private Date publicationDate;
// サブカテゴリーID // サブカテゴリーID
@Column(name = "subcategory_id", nullable = false) @Column(name = "book_subcategory_id", nullable = false)
private Integer subcategoryId; private Integer subcategoryId;
// // カテゴリー名 // // カテゴリー名

View File

@@ -1,9 +1,10 @@
package com.example.demo.repository; package com.example.demo.repository;
import java.awt.print.Book;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import com.example.demo.entity.Book;
public interface BookRepository extends JpaRepository<Book, Integer>{ public interface BookRepository extends JpaRepository<Book, Integer>{
} }

View File

@@ -7,5 +7,5 @@ import com.example.demo.entity.Book;
public interface BookService { public interface BookService {
String booklist(Book book); String booklist(Book book);
List<Book> findAll(); List<java.awt.print.Book> findAll();
} }

View File

@@ -1,6 +1,6 @@
package com.example.demo.service; package com.example.demo.service;
import java.awt.print.Book;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -10,23 +10,25 @@ import com.example.demo.entity.Book;
import com.example.demo.repository.BookRepository; import com.example.demo.repository.BookRepository;
@Service @Service
public class BookServiceImpl implements BookService{ public class BookServiceImpl{
@Autowired @Autowired
private BookRepository bookRepository; private BookRepository bookRepository;
// @Override
// public String booklist(com.example.demo.entity.Book book) {
// Book booklist = new Book();
// booklist.setBookId(book.getBookId());
//
// return null;
// }
@Override
public String booklist(Book book) {
Book booklist = new Book();
booklist.set
return null;
}
@Override
public List<Book> findAll() { public List<Book> findAll() {
// TODO 自動生成されたメソッド・スタブ return bookRepository.findAll();
return null;
} }

View File

@@ -1,5 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html>
<html xmlns:th="http://www.thymeleaf.org">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
@@ -7,19 +8,68 @@
</head> </head>
<body> <body>
<form method="get" action="bookLend"> <div class="container">
<h1>社内図書一覧</h1>
<div class="float-end">
</div>
<form method="get" action="bookLend">
<table class="table table-striped">
<thead>
<tr>
<th>図書ID</th>
<th>ISBN</th>
<th>書籍名</th>
<th>著者名</th>
<th>出版社</th>
<th>出版日</th>
<th>カテゴリー名</th>
<th>サブカテゴリー名</th>
<th>保管場所</th>
<th>貸出状態</th>
<th>本の状態</th>
<th>備考</th>
<th>登録日時</th>
<th>更新日時</th>
<th>寄贈者</th>
<th>寄贈者</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr th:each="b : ${book}">
<td th:text="*{b.bookId}"></td>
<td th:text="*{b.bookManageId}"></td>
<td th:text="*{b.title}"></td>
<td th:text="*{b.isbn}"></td>
<td th:text="*{b.author}"></td>
<td th:text="*{b.publisher}"></td>
<td th:text="*{b.publicationDate}"></td>
<td th:text="*{b.subcategoryId}"></td>
<td th:text="*{b.locationId}"></td>
<td th:text="*{b.condition}"></td>
<td th:text="*{b.createdAt}"></td>
<td th:text="*{b.updatedAt}"></td>
<td th:text="*{b.isDeleted}"></td>
<td th:text="*{b.donorId}"></td>
<td th:text="*{b.description}"></td>
<td th:text="*{b.bookApproval}"></td>
</tr>
</tbody>
</table>
<button type="submit" class="btn-login"> <button type="submit" class="btn-login">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round"> stroke-linejoin="round">
<path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4" /> <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" /> <polyline points="10 17 15 12 10 7" />
<line x1="15" y1="12" x2="3" y2="12" /> <line x1="15" y1="12" x2="3" y2="12" />
</svg> </svg>
貸出 貸出
</button> </button>
</form> </form>
</body> </body>