[ADD] 貸出中図書一覧の返却処理を追加しました。

This commit is contained in:
y-kumaki
2026-09-29 13:44:21 +09:00
parent da5cc25c34
commit 441d91d1e2
4 changed files with 83 additions and 61 deletions

View File

@@ -1,13 +1,11 @@
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 org.springframework.web.bind.annotation.RequestParam;
import com.example.demo.entity.BookLend;
import com.example.demo.service.BookLendService; import com.example.demo.service.BookLendService;
@@ -20,12 +18,19 @@ public class LendListController {
@GetMapping("/lendList") @GetMapping("/lendList")
public String list(Model model) { public String list(Model model) {
List<BookLend> aaa = lendlistService.findAll();
// findAllを使って、DBから一覧を取得 でバックで取得したのを確認 // findAllを使って、DBから一覧を取得 でバックで取得したのを確認
model.addAttribute("list",lendlistService.findAll()); model.addAttribute("list",lendlistService.findAll());
return "lendList"; return "lendList";
} }
@GetMapping("/return-book")
public String retun(@RequestParam(name="lendId") int returnBook){
lendlistService.regist(returnBook);
return "bookLendResult";
}
} }

View File

@@ -4,6 +4,7 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.example.demo.entity.BookLend; import com.example.demo.entity.BookLend;
import com.example.demo.repository.BookLendRepository; import com.example.demo.repository.BookLendRepository;
@@ -16,6 +17,18 @@ public class BookLendService {
public List<BookLend> findAll() { public List<BookLend> findAll() {
return bookLendRepository.findBybookStatus(1); return bookLendRepository.findBybookStatus(1);
}
@Transactional
public void regist(Integer lendId) {
BookLend booklend = bookLendRepository.findById(lendId).orElse(null);
booklend.setBookStatus(0);
bookLendRepository.save(booklend);
} }
} }

View File

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>貸出中図書、返却処理結果画面</title>
<link rel="stylesheet" th:href="@{/css/style.css}">
</head>
<body>
<h1>返却処理が完了しました。</h1>
<td>
<form th:action="@{/lendList}" method="get">
<button type="submit" th:value="貸出">貸出中図書一覧に戻る</button>
</td>
</body>
</html>

View File

@@ -10,69 +10,53 @@
<body> <body>
<h1>貸出中図書一覧</h1> <h1>貸出中図書一覧</h1>
<!-- action先要修正 -->
<form action="/lendList" method="GET">
<input type="submit" value="返却" class="btn">
<table> <table>
<thead>
<tr>
<th>社員ID</th>
<th>社員名</th>
<th>管理ID</th>
<th>タイトル</th>
<th>返却予定日</th>
</tr>
</thead>
<tbody>
<tr th:each="booklist : ${list}">
<td th:text="*{booklist.employeeBooklend.employeeId}"></td>
<td th:text="*{booklist.employeeBooklend.employeeName}"></td>
<td th:text="*{booklist.book.bookManageId}"></td>
<td th:text="*{booklist.book.title}"></td>
<td th:text="*{booklist.bookReturnDate}"></td>
<td>
<form th:action="@{/return-book}" method="get">
<button type="submit" name="lendId" th:value="${booklist.lendId}"
onclick="return MoveCheck();">返却
</button>
</form>
</td>
</tr>
</tbody>
<thead>
<tr>
<th>社員ID</th>
<th>社員名</th>
<th>管理ID</th>
<th>タイトル</th>
<th>返却予定日</th>
<th>超過日数</th>
</tr>
</thead>
<tbody>
<tr th:each="booklist : ${list}">
<td th:text="*{booklist.employeeBooklend.employeeId}"></td>
<td th:text="*{booklist.employeeBooklend.employeeName}"></td>
<td th:text="*{booklist.book.bookManageId}"></td>
<td th:text="*{booklist.book.title}"></td>
<td th:text="*{booklist.bookReturnDate}"></td>
<!-- <td th:text="*{booklist.}"></td>-->
</tr>
</tbody>
</table> </table>
</form>
<!-- 以下ポップアップ -->
<div id="registerModal" class="modal-overlay">
<div class="modal">
<div class="modal-message">
返却処理が完了しました!
</div>
<div class="modal-buttons">
<!-- OK -->
<form method="get" action="/lendList">
<button type="submit" class="modal-btn">
OK
</button>
</form>
<script>
</div> function MoveCheck() {
return window.confirm("返却処理を実行します。よろしいですか?");
</div> }
</div>
</script>
</body> </body>