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

View File

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

View File

@@ -1,8 +1,12 @@
package com.example.demo.entity; package com.example.demo.entity;
import java.util.ArrayList;
import java.util.List;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import lombok.Data; import lombok.Data;
@@ -12,11 +16,13 @@ import lombok.Data;
@Table(name="book_category") @Table(name="book_category")
public class BookCategory { public class BookCategory {
@Id @Id
@Column(name = "book_category_id") @Column(name = "book_category_id")
private Integer bookCategoryId; private Integer bookCategoryId;
@Column(name = "book_category_name") @Column(name = "book_category_name")
private String bookCategoryName; 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; package com.example.demo.entity;
import java.util.ArrayList;
import java.util.List;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType; import jakarta.persistence.GenerationType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import lombok.Data; import lombok.Data;
@@ -26,4 +30,8 @@ public class Employee {
//部署ID //部署ID
@Column(name = "department_id", nullable = false) @Column(name = "department_id", nullable = false)
private Integer departmentId; 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>
<th>寄贈者</th> <th>??</th>
<th>操作</th> <th>操作</th>
</tr> </tr>
</thead> </thead>
@@ -46,13 +46,14 @@
<td th:text="*{b.author}"></td> <td th:text="*{b.author}"></td>
<td th:text="*{b.publisher}"></td> <td th:text="*{b.publisher}"></td>
<td th:text="*{b.publicationDate}"></td> <td th:text="*{b.publicationDate}"></td>
<td th:text="*{b.subcategoryId}"></td> <td th:text="*{b.bookSubcategory.bookSubcategoryName}"></td>
<td th:text="*{b.locationId}"></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.condition}"></td>
<td th:text="*{b.createdAt}"></td> <td th:text="*{b.createdAt}"></td>
<td th:text="*{b.updatedAt}"></td> <td th:text="*{b.updatedAt}"></td>
<td th:text="*{b.isDeleted}"></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.description}"></td>
<td th:text="*{b.bookApproval}"></td> <td th:text="*{b.bookApproval}"></td>
</tr> </tr>