[edit] カテゴリー名・サブカテゴリー名表示の編集をしました

This commit is contained in:
s-tajihi
2026-09-24 16:09:42 +09:00
parent 1488f42039
commit 24caa7f6e2
7 changed files with 109 additions and 39 deletions

View File

@@ -1,10 +1,13 @@
package com.example.demo.controller;
import java.util.List;
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 com.example.demo.entity.Book;
import com.example.demo.service.BookServiceImpl;
@Controller
@@ -15,6 +18,8 @@ public class BookController {
@GetMapping("/book")
public String book(Model model) {
List<Book> aaa = bookService.findAll();
// DBから取得したデータをHTMLで扱えるようにする
model.addAttribute("book",bookService.findAll());
return "book";

View File

@@ -7,6 +7,8 @@ import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Data;
@@ -15,11 +17,11 @@ import lombok.Data;
@Data
@Table(name = "book")
public class Book {
//図書ID
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "book_Id", nullable = false)
@Column(name = "book_id", nullable = false)
private int bookId;
// 図書管理ID(BK-1など)
@@ -46,29 +48,16 @@ public class Book {
@Column(name = "publication_date", nullable = true)
private Date publicationDate;
// サブカテゴリーID
@Column(name = "book_subcategory_id", nullable = false)
private Integer subcategoryId;
// サブカテゴリーID!!
@ManyToOne
@JoinColumn(name = "book_subcategory_id", nullable = false)
private BookSubcategory bookSubcategory;
// // カテゴリー名
// @Column(name = "category_name", nullable = false)
// private String categoryName;
//
// // サブカテゴリー名
// @Column(name = "subcategory_name", nullable = false)
// private String subcategoryName;
// 保管場所
@ManyToOne
@JoinColumn(name = "location_id", nullable = false)
private StorageLocation storageLocation;
// 保管場所ID
@Column(name = "location_id", nullable = false)
private Integer locationId;
// // 保管場所
// @Column(name = "location_name", nullable = false)
// private String locationName;
// // 貸出状態
// @Column(name = "book_Id", nullable = false)
// private int bookStatus;
// 本の状態
@Column(name = "condition_s", nullable = false)
@@ -86,17 +75,10 @@ public class Book {
@Column(name = "is_deleted", nullable = false)
private Integer isDeleted;
// 寄贈者社員ID
@Column(name = "donor_id", nullable = true)
private String donorId;
// // 寄贈者社員名
// @Column(name = "donor_name", nullable = true)
// private String donorName;
// //返却予定日
// @Column(name = "return_date", nullable = false)
// private Date returnDate;
// 寄贈者社員ID??
@ManyToOne
@JoinColumn(name = "donor_id", nullable = false)
private Employee employee;
//備考
@Column(name = "description", nullable = true)

View File

@@ -1,8 +1,12 @@
package com.example.demo.entity;
import java.util.ArrayList;
import java.util.List;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.Data;
@@ -12,11 +16,13 @@ import lombok.Data;
@Table(name="book_category")
public class BookCategory {
@Id
@Column(name = "book_category_id")
private Integer bookCategoryId;
@Column(name = "book_category_name")
private String bookCategoryName;
@OneToMany(mappedBy = "bookCategory")
private List<BookSubcategory> BookSubcategories = new ArrayList<>();
}

View File

@@ -0,0 +1,34 @@
package com.example.demo.entity;
import java.util.ArrayList;
import java.util.List;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.Data;
@Entity
@Data
@Table(name = "book_subcategory")
public class BookSubcategory {
@Id
@Column(name = "book_subcategory_id")
private Integer bookSubcategoryId;
@ManyToOne
@JoinColumn(name = "book_category_id", nullable = false)
private BookCategory bookCategory;
@Column(name = "book_subcategory_name")
private String bookSubcategoryName;
@OneToMany(mappedBy = "bookSubcategory")
private List<Book> Books = new ArrayList<>();
}

View File

@@ -1,10 +1,14 @@
package com.example.demo.entity;
import java.util.ArrayList;
import java.util.List;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.Data;
@@ -26,4 +30,8 @@ public class Employee {
//部署ID
@Column(name = "department_id", nullable = false)
private Integer departmentId;
@OneToMany(mappedBy = "employee")
private List<Book> employees = new ArrayList<>();
}

View File

@@ -0,0 +1,34 @@
package com.example.demo.entity;
import java.util.ArrayList;
import java.util.List;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.Data;
@Entity // このクラスがDBのテーブルに対応することを表す
@Data
@Table(name = "storage_location")
public class StorageLocation {
//保管場所ID
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "location_id", nullable = false)
private int locationId;
// 保管場所名
@Column(name = "location_name", nullable = false)
private String locationName;
@OneToMany(mappedBy = "storageLocation")
private List<Book> Location = new ArrayList<>();
}

View File

@@ -32,7 +32,7 @@
<th>登録日時</th>
<th>更新日時</th>
<th>寄贈者</th>
<th>寄贈者</th>
<th>??</th>
<th>操作</th>
</tr>
</thead>
@@ -46,13 +46,14 @@
<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.bookSubcategory.bookSubcategoryName}"></td>
<td th:text="*{b.bookSubcategory.bookCategory.bookCategoryName}"></td>
<td th:text="*{b.storageLocation.locationName}"></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.donorId != null ? b.donorId : '-'}"></td>
<td th:text="*{b.description}"></td>
<td th:text="*{b.bookApproval}"></td>
</tr>