Compare commits
5 Commits
y-watanabe
...
8c633eabf4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c633eabf4 | ||
|
|
a562e23919 | ||
|
|
fa1846dbd7 | ||
|
|
d6134fab10 | ||
|
|
da5cc25c34 |
@@ -1,21 +1,59 @@
|
||||
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.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import com.example.demo.entity.Employee;
|
||||
import com.example.demo.repository.EmployeeRepository;
|
||||
import com.example.demo.service.BookServiceImpl;
|
||||
import com.example.demo.service.EmployeeService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class BookLendController {
|
||||
|
||||
@Autowired
|
||||
private final BookServiceImpl bookServiceImpl;
|
||||
|
||||
@Autowired
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
@PostMapping("/bookLend")
|
||||
public String bookLend(Model model) {
|
||||
@Autowired
|
||||
private EmployeeService employeeService;
|
||||
|
||||
// @PostMapping("/bookLend")
|
||||
// public String bookLend(Model model) {
|
||||
// return "bookLend";
|
||||
// }
|
||||
|
||||
// @PostMapping("/bookLend/{id}")
|
||||
// public String bookLend(@PathVariable int id, Model model) {
|
||||
// System.out.println(id);
|
||||
// model.addAttribute("book", bookServiceImpl.findById(id));
|
||||
// return "bookLend";
|
||||
// }
|
||||
|
||||
@PostMapping("/bookLend/{id}")
|
||||
public String bookLend(@PathVariable int id,Employee employee, Model model) {
|
||||
|
||||
// 図書ID取得
|
||||
model.addAttribute("book", bookServiceImpl.findById(id));
|
||||
|
||||
// 社員ID取得(プルダウン用)
|
||||
List<Employee> empList = employeeService.findAll();
|
||||
|
||||
model.addAttribute("bookLend", employeeService.findAll());
|
||||
|
||||
// model.addAttribute("employeeList", employeeRepository.findByEmployeeId(employee.getEmployeeId()));
|
||||
// model.addAttribute("bookLend", employee);
|
||||
|
||||
return "bookLend";
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.example.demo.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -8,4 +10,6 @@ import com.example.demo.entity.BookLend;
|
||||
@Repository
|
||||
public interface BookLendRepository extends JpaRepository<BookLend, Integer> {
|
||||
|
||||
List<BookLend> findBybookStatus(Integer bookStatus);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import com.example.demo.entity.Book;
|
||||
import com.example.demo.repository.BookRepository;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class BookServiceImpl {
|
||||
|
||||
@Autowired
|
||||
@@ -18,8 +24,18 @@ public class BookServiceImpl {
|
||||
return bookRepository.findAll();
|
||||
}
|
||||
|
||||
public List<Book> findBooks(String keyword){
|
||||
public List<Book> findBooks(String keyword) {
|
||||
return bookRepository.searchBooks(keyword);
|
||||
}
|
||||
|
||||
public Book findById(int bookId) {
|
||||
Optional<Book> book = bookRepository.findById(bookId);
|
||||
if (book.isEmpty()) {
|
||||
throw new ResponseStatusException(
|
||||
HttpStatus.NOT_FOUND, "図書情報が見つかりません");
|
||||
}
|
||||
|
||||
return book.get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
<tbody>
|
||||
<tr th:each="book : ${book}" th:if="${book.bookManageId != null}">
|
||||
|
||||
<td th:hidden="*{book.bookId}"></td>
|
||||
<td th:text="*{book.bookManageId}"></td>
|
||||
<td th:text="*{book.isbn}"></td>
|
||||
<td th:text="*{book.title}"></td>
|
||||
@@ -106,8 +107,8 @@
|
||||
|
||||
<td th:if="${session.loginEmployee.adminFlag == 1}">
|
||||
|
||||
<form method="post" action="/bookLend">
|
||||
<input type="hidden" name="bookManageId" th:value="*{book.bookManageId}">
|
||||
<form method="post" th:action="@{/bookLend/{id}(id=${book.bookId})}">
|
||||
<input type="hidden" name="id" th:value="*{book.bookId}">
|
||||
<button type="submit"
|
||||
th:disabled="*{book.bookLends != null && book.bookLends.bookStatus == 1}">
|
||||
貸出
|
||||
|
||||
Reference in New Issue
Block a user