diff --git a/src/main/java/com/example/demo/controller/BookLendController.java b/src/main/java/com/example/demo/controller/BookLendController.java index 9d1b1dc..06e2c20 100644 --- a/src/main/java/com/example/demo/controller/BookLendController.java +++ b/src/main/java/com/example/demo/controller/BookLendController.java @@ -1,17 +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.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; @@ -24,45 +20,19 @@ public class BookLendController { @Autowired private EmployeeRepository employeeRepository; - - @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") + public String bookLend(Model model) { + return "bookLend"; + } @PostMapping("/bookLend/{id}") - public String bookLend(@PathVariable int id,Employee employee, Model model) { - - // 図書ID取得 + public String bookLend(@PathVariable int id, Model model) { + System.out.println(id); model.addAttribute("book", bookServiceImpl.findById(id)); - - // 社員ID取得(プルダウン用) - List empList = employeeService.findAll(); - - model.addAttribute("bookLend", employeeService.findAll()); - -// model.addAttribute("employeeList", employeeRepository.findByEmployeeId(employee.getEmployeeId())); -// model.addAttribute("bookLend", employee); - - return "bookLend"; - } - - // 社員IDを取得してプルダウンに表示させる - @PostMapping("/bookLend/employeeId") - public String selectEmployeeId(Employee employee, Model model) { - model.addAttribute("employeeList", employeeRepository.findByEmployeeId(employee.getEmployeeId())); - model.addAttribute("bookLend", employee); return "bookLend"; } + + } diff --git a/src/main/java/com/example/demo/service/EmployeeService.java b/src/main/java/com/example/demo/service/EmployeeService.java new file mode 100644 index 0000000..0f94b99 --- /dev/null +++ b/src/main/java/com/example/demo/service/EmployeeService.java @@ -0,0 +1,24 @@ +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.Employee; +import com.example.demo.repository.EmployeeRepository; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class EmployeeService { + + @Autowired + private EmployeeRepository employeeRepository; + + public List findAll() { + return employeeRepository.findAll(); + } + +} diff --git a/src/main/resources/templates/bookLend.html b/src/main/resources/templates/bookLend.html index fe4a3c2..e852201 100644 --- a/src/main/resources/templates/bookLend.html +++ b/src/main/resources/templates/bookLend.html @@ -13,181 +13,109 @@

- 以下の図書を貸出します。貸出先と貸出日・返却予定日を入力してください。 + 以下の図書を貸出します。貸出先の社員IDと返却予定日を入力してください。

図書情報

-
- - - + - - +
+
- 図書管理ID -
- (図書管理IDをここに表示させる) -
+ + + + + + + + - - + + + + + + + + - - + - - - - - - - - - - - -
図書管理ID図書タイトル著者名ISBN
- 図書タイトル -
- (タイトルをここに表示させる) -
- 著者名 - - (著者名をここに表示させる) -
- ISBN - - (ISBNをここに表示させる) -
-
- -

- 社員情報 -

- -
- -
- - - - - - +
-
- +

+ 社員情報 +

- +
-
+
-
+ -

- 貸出・返却日入力 -

+ -
- -
- - - - - -
- ※ 現在の日付が自動で設定されます。 +
-
+

+ 貸出・返却日入力 +

- +
- +
+ + + +

+

+ +
+ +
+ + + + + +
+ ※ カレンダーから日付を選択してください。 +
+ +
+ ※ 現在の日付より前は選択できません。 +
-
- ※ 数値(1以上)で入力してください。
-
- - - - - -
- ※ カレンダーから日付を選択してください。 -
- -
- ※ 現在の日付より前は選択できません。 -
- -
- -
- -
- - +

注意事項 - +

-
    -
  • - 貸出処理を行うと、対象の図書のステータスが「貸出中」に変更されます。 -
  • +

    + 貸出処理を行うと、対象の図書のステータスが「貸出中」に変更されます。 +

    -
  • - 返却予定日を必ず指定してください。 -
  • -
+ + -
- - -
- -
- -
- -
+ @@ -201,6 +129,19 @@ } } + // カレンダーを当日以前の日付を入力できないようにする + const today = new Date(); + function dateFormat(today, format) { + format = format.replace("YYYY", today.getFullYear()); + format = format.replace("MM", ("0" + (today.getMonth() + 1)).slice(-2)); + format = format.replace("DD", ("0" + today.getDate()).slice(-2)); + return format; + } + + const data = dateFormat(today, 'YYYY-MM-DD'); + const field = document.getElementById('returnDate'); + field.setAttribute("min", data); +