Merge branch 's-tajihi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/ShareBooks_new into y-watanabe
This commit is contained in:
@@ -1,15 +1,28 @@
|
|||||||
package com.example.demo.controller;
|
package com.example.demo.controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
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
|
@Controller
|
||||||
public class BookController {
|
public class BookController {
|
||||||
@PostMapping("/book")
|
@Autowired
|
||||||
public String book() {
|
private BookServiceImpl bookService;
|
||||||
return "book";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@GetMapping("/book")
|
||||||
|
public String book(Model model) {
|
||||||
|
|
||||||
|
List<Book> aaa = bookService.findAll();
|
||||||
|
|
||||||
|
// DBから取得したデータをHTMLで扱えるようにする
|
||||||
|
model.addAttribute("book",bookService.findAll());
|
||||||
|
return "book";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
95
src/main/java/com/example/demo/entity/Book.java
Normal file
95
src/main/java/com/example/demo/entity/Book.java
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
package com.example.demo.entity;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
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.OneToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Entity // このクラスがDBのテーブルに対応することを表す
|
||||||
|
@Data
|
||||||
|
@Table(name = "book")
|
||||||
|
public class Book {
|
||||||
|
|
||||||
|
//図書ID
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "book_id", nullable = false)
|
||||||
|
private int bookId;
|
||||||
|
|
||||||
|
// 図書管理ID(BK-1など)
|
||||||
|
@Column(name = "book_manage_id", nullable = true)
|
||||||
|
private String bookManageId;
|
||||||
|
|
||||||
|
// タイトル
|
||||||
|
@Column(name = "title", nullable = false)
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
//ISBN
|
||||||
|
@Column(name = "isbn", nullable = false)
|
||||||
|
private String isbn;
|
||||||
|
|
||||||
|
// 著者名
|
||||||
|
@Column(name = "author", nullable = false)
|
||||||
|
private String author;
|
||||||
|
|
||||||
|
// 出版社
|
||||||
|
@Column(name = "publisher", nullable = true)
|
||||||
|
private String publisher;
|
||||||
|
|
||||||
|
// 出版日
|
||||||
|
@Column(name = "publication_date", nullable = true)
|
||||||
|
private Date publicationDate;
|
||||||
|
|
||||||
|
// サブカテゴリーID!!
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "book_subcategory_id", nullable = false)
|
||||||
|
private BookSubcategory bookSubcategory;
|
||||||
|
|
||||||
|
// 保管場所
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "location_id", nullable = false)
|
||||||
|
private StorageLocation storageLocation;
|
||||||
|
|
||||||
|
|
||||||
|
// 本の状態
|
||||||
|
@Column(name = "condition_s", nullable = false)
|
||||||
|
private int condition;
|
||||||
|
|
||||||
|
// 登録日
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private Date createdAt;
|
||||||
|
|
||||||
|
// 更新日
|
||||||
|
@Column(name = "updated_at", nullable = false)
|
||||||
|
private Date updatedAt;
|
||||||
|
|
||||||
|
//削除フラグ
|
||||||
|
@Column(name = "is_deleted", nullable = false)
|
||||||
|
private Integer isDeleted;
|
||||||
|
|
||||||
|
// 寄贈者社員ID??
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "donor_id", nullable = false)
|
||||||
|
private Employee employee;
|
||||||
|
|
||||||
|
//備考
|
||||||
|
@Column(name = "description", nullable = true)
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
//申請承認フラグ
|
||||||
|
@Column(name = "book_approval", nullable = false)
|
||||||
|
private Integer bookApproval;
|
||||||
|
|
||||||
|
@OneToOne(mappedBy = "book")
|
||||||
|
private BookLend bookLends;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<>();
|
||||||
}
|
}
|
||||||
46
src/main/java/com/example/demo/entity/BookLend.java
Normal file
46
src/main/java/com/example/demo/entity/BookLend.java
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package com.example.demo.entity;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.OneToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Entity // このクラスがDBのテーブルに対応することを表す
|
||||||
|
@Data
|
||||||
|
@Table(name = "book_lend")
|
||||||
|
public class BookLend {
|
||||||
|
//貸出ID
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "lend_Id", nullable = false)
|
||||||
|
private int lendId;
|
||||||
|
|
||||||
|
// 図書管理ID(BK-1など)
|
||||||
|
@OneToOne
|
||||||
|
@JoinColumn(name = "book_manage_id", referencedColumnName = "book_manage_id",nullable = false)
|
||||||
|
private Book book;
|
||||||
|
|
||||||
|
// 図書管理ID(BK-1など)
|
||||||
|
@Column(name = "employee_id", nullable = false)
|
||||||
|
private Integer employeeId;
|
||||||
|
|
||||||
|
// 貸出日
|
||||||
|
@Column(name = "book_lend_date", nullable = false)
|
||||||
|
private Date bookLendDate;
|
||||||
|
|
||||||
|
// 返却日
|
||||||
|
@Column(name = "book_return_date", nullable = false)
|
||||||
|
private Date bookReturnDate;
|
||||||
|
|
||||||
|
// 貸出状態
|
||||||
|
@Column(name = "book_status", nullable = false)
|
||||||
|
private Integer bookStatus;
|
||||||
|
}
|
||||||
34
src/main/java/com/example/demo/entity/BookSubcategory.java
Normal file
34
src/main/java/com/example/demo/entity/BookSubcategory.java
Normal 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<>();
|
||||||
|
|
||||||
|
}
|
||||||
37
src/main/java/com/example/demo/entity/Employee.java
Normal file
37
src/main/java/com/example/demo/entity/Employee.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
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 = "employee")
|
||||||
|
public class Employee {
|
||||||
|
//社員ID
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "employee_Id", nullable = false)
|
||||||
|
private int employeeId;
|
||||||
|
|
||||||
|
// 社員名
|
||||||
|
@Column(name = "employee_name", nullable = false)
|
||||||
|
private String employeeName;
|
||||||
|
|
||||||
|
//部署ID
|
||||||
|
@Column(name = "department_id", nullable = false)
|
||||||
|
private Integer departmentId;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "employee")
|
||||||
|
private List<Book> employees = new ArrayList<>();
|
||||||
|
|
||||||
|
}
|
||||||
34
src/main/java/com/example/demo/entity/StorageLocation.java
Normal file
34
src/main/java/com/example/demo/entity/StorageLocation.java
Normal 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<>();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
5
src/main/java/com/example/demo/form/BookForm.java
Normal file
5
src/main/java/com/example/demo/form/BookForm.java
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package com.example.demo.form;
|
||||||
|
|
||||||
|
public class BookForm {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.example.demo.repository;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import com.example.demo.entity.Book;
|
||||||
|
|
||||||
|
public interface BookRepository extends JpaRepository<Book, Integer>{
|
||||||
|
|
||||||
|
}
|
||||||
11
src/main/java/com/example/demo/service/BookService.java
Normal file
11
src/main/java/com/example/demo/service/BookService.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
35
src/main/java/com/example/demo/service/BookServiceImpl.java
Normal file
35
src/main/java/com/example/demo/service/BookServiceImpl.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package com.example.demo.service;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.example.demo.entity.Book;
|
||||||
|
import com.example.demo.repository.BookRepository;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,25 +1,100 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>社内図書一覧</title>
|
<title>社内図書一覧</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<form method="post" 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>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
<tr th:each="book : ${book}">
|
||||||
|
|
||||||
|
<td th:text="*{book.bookManageId}"></td>
|
||||||
|
<td th:text="*{book.isbn}"></td>
|
||||||
|
<td th:text="*{book.title}"></td>
|
||||||
|
<td th:text="*{book.author}"></td>
|
||||||
|
<td th:text="*{book.publisher}"></td>
|
||||||
|
<td th:text="*{book.publicationDate}"></td>
|
||||||
|
<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.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>
|
||||||
|
|
||||||
|
|
||||||
<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">
|
</tr>
|
||||||
<button type="submit" class="btn-login">
|
</tbody>
|
||||||
<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>
|
</table>
|
||||||
更新
|
|
||||||
</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>
|
||||||
|
|
||||||
|
<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>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user