Compare commits
9 Commits
h-seya
...
y-watanabe
| Author | SHA1 | Date | |
|---|---|---|---|
| 47ce48e323 | |||
| c5c5c3dcc9 | |||
| f8973bd47f | |||
| 01ffb88358 | |||
| 10f7551bbd | |||
| 229f578d69 | |||
|
|
df4cc6465c | ||
|
|
27a4fa71c4 | ||
|
|
da5cc25c34 |
@@ -47,13 +47,15 @@ private BookInsertRepository bookInsertRepository;
|
||||
// 初期表示: 空のformを渡す(th:fieldの初期値が空になる)
|
||||
|
||||
// 確認画面から戻る: POSTされた入力中の値がformに入ったまま入力画面へ
|
||||
//入力内容確認してOKであれば確認画面へ
|
||||
@PostMapping("/bookInsertConfirm")
|
||||
public String bookInsertConfirm(@Validated BookInsert bookInsert, BindingResult result, Model model) {
|
||||
if (result.hasErrors()) {
|
||||
model.addAttribute("nextBookManageId", bookInsertService.createBookManageId());
|
||||
model.addAttribute("categoryList", categoryRepository.findAll());
|
||||
if (bookInsert.getBookCategoryId() != null) { //nullじゃなかったら
|
||||
model.addAttribute("subCategoryList",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
|
||||
model.addAttribute("subCategoryList",
|
||||
subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
|
||||
//そのカテゴリに属するサブカテゴリを持ってくる
|
||||
} else {
|
||||
model.addAttribute("subCategoryList", subCategoryRepository.findAll());
|
||||
@@ -68,27 +70,18 @@ private BookInsertRepository bookInsertRepository;
|
||||
return "bookInsertConfirm";
|
||||
}
|
||||
|
||||
//確認画面から「もどる」ボタンを押したら入力画面に戻る
|
||||
@PostMapping("/bookInsert")
|
||||
public String bookInsertBack(BookInsert bookInsert,Model model) {
|
||||
model.addAttribute("nextBookManageId",bookInsertService.createBookManageId());
|
||||
model.addAttribute("categoryList",categoryRepository.findAll());
|
||||
if(bookInsert.getBookCategoryId() !=null) {
|
||||
model.addAttribute("subCategoryList",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
|
||||
} else{
|
||||
model.addAttribute("subCategoryList",subCategoryRepository.findAll());
|
||||
}
|
||||
model.addAttribute("locationList",storageLocationRepository.findAll());
|
||||
model.addAttribute("bookInsert",bookInsert);
|
||||
return "bookInsert";
|
||||
}
|
||||
|
||||
@PostMapping("/bookInsert/category")
|
||||
public String changeCategory(BookInsert bookInsert, Model model) {
|
||||
//カテゴリプルダウンに表示するデータを取得
|
||||
model.addAttribute("nextBookManageId", bookInsertService.createBookManageId());
|
||||
model.addAttribute("categoryList", categoryRepository.findAll());
|
||||
model.addAttribute("subCategoryList",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
|
||||
if (bookInsert.getBookCategoryId() != null) { //nullじゃなかったら
|
||||
model.addAttribute("subCategoryList",
|
||||
subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
|
||||
//そのカテゴリに属するサブカテゴリを持ってくる
|
||||
} else {
|
||||
model.addAttribute("subCategoryList", subCategoryRepository.findAll());
|
||||
}
|
||||
model.addAttribute("locationList", storageLocationRepository.findAll());
|
||||
model.addAttribute("bookInsert", bookInsert);
|
||||
|
||||
@@ -97,13 +90,7 @@ private BookInsertRepository bookInsertRepository;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//画面で選択したカテゴリbookInsert.getBookCategoryId()に選択した結果をいれる
|
||||
//subCategoryRepository.findBookCategory_BookCategoryId(bookInsert.getBookCategoryId(1)));
|
||||
//「カテゴリIDが1のサブカテゴリを取ってくる」
|
||||
//model.addAttribute("subCategoryList",取得結果)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
@@ -11,7 +14,9 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import com.example.demo.entity.AccountEntity;
|
||||
import com.example.demo.entity.Employee;
|
||||
import com.example.demo.form.LoginForm;
|
||||
import com.example.demo.repository.EmployeeRepository;
|
||||
import com.example.demo.service.LoginService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -21,12 +26,20 @@ import lombok.RequiredArgsConstructor;
|
||||
public class LoginController {
|
||||
|
||||
private final LoginService loginService;
|
||||
@Autowired
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
|
||||
// Boot起動直後にログイン画面に移動する用のメソッド
|
||||
@GetMapping("/")
|
||||
public String index(HttpSession session) {
|
||||
public String index(Model model,HttpSession session) {
|
||||
if (session.getAttribute("loginEmployee") != null) {
|
||||
return "redirect:/topmenu";
|
||||
if(session.getAttribute("EmployeeId") != null) {
|
||||
|
||||
List<Employee> emrp = employeeRepository.findByEmployeeId((Integer)session.getAttribute("EmployeeId") );
|
||||
model.addAttribute("LoginName",emrp.getFirst().getEmployeeName());
|
||||
}
|
||||
return "topmenu";
|
||||
}
|
||||
return "redirect:/login";
|
||||
}
|
||||
@@ -34,7 +47,12 @@ public class LoginController {
|
||||
@GetMapping("/login")
|
||||
public String loginForm(Model model, HttpSession session) {
|
||||
if (session.getAttribute("loginEmployee") != null) {
|
||||
return "redirect:/topmenu";
|
||||
if(session.getAttribute("EmployeeId") != null) {
|
||||
|
||||
List<Employee> emrp = employeeRepository.findByEmployeeId((Integer)session.getAttribute("EmployeeId") );
|
||||
model.addAttribute("LoginName",emrp.getFirst().getEmployeeName());
|
||||
}
|
||||
return "topmenu";
|
||||
}
|
||||
|
||||
model.addAttribute("loginForm", new LoginForm());
|
||||
@@ -61,7 +79,13 @@ public class LoginController {
|
||||
}
|
||||
|
||||
session.setAttribute("loginEmployee", accountEntity);
|
||||
return "redirect:/topmenu";
|
||||
|
||||
List<Employee> emrp = employeeRepository.findByEmployeeId(accountEntity.getEmployee().getEmployeeId());
|
||||
model.addAttribute("LoginName",emrp.getFirst().getEmployeeName());
|
||||
session.setAttribute("EmployeeId", accountEntity.getEmployee().getEmployeeId());
|
||||
|
||||
|
||||
return "topmenu";
|
||||
}
|
||||
|
||||
// ログアウト処理
|
||||
@@ -73,7 +97,13 @@ public class LoginController {
|
||||
|
||||
// 各画面からトップメニューへの遷移用
|
||||
@GetMapping("/topmenu")
|
||||
public String showTopMenu() {
|
||||
public String showTopMenu(Model model,HttpSession session) {
|
||||
|
||||
if(session.getAttribute("EmployeeId") != null) {
|
||||
|
||||
List<Employee> emrp = employeeRepository.findByEmployeeId((Integer)session.getAttribute("EmployeeId") );
|
||||
model.addAttribute("LoginName",emrp.getFirst().getEmployeeName());
|
||||
}
|
||||
return "topmenu";
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class BookLendService {
|
||||
private BookLendRepository bookLendRepository;
|
||||
|
||||
public List<BookLend> findAll() {
|
||||
return bookLendRepository.findAll();
|
||||
return bookLendRepository.findBybookStatus(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
@@ -17,7 +17,7 @@
|
||||
<div class="header-right">
|
||||
|
||||
<span class="user">
|
||||
テストユーザー(一般)
|
||||
<h1 th:text="${LoginName}"></h1>
|
||||
</span>
|
||||
|
||||
<a class="button-link" th:href="@{/logout}">
|
||||
@@ -61,6 +61,7 @@
|
||||
<hr>
|
||||
|
||||
<!-- ===== 管理者のみ ===== -->
|
||||
<th th:if="${session.loginEmployee.adminFlag == 1}">
|
||||
|
||||
<a class="card" href="/bookInsert">
|
||||
|
||||
@@ -71,6 +72,7 @@
|
||||
</p>
|
||||
</a>
|
||||
|
||||
|
||||
<hr>
|
||||
|
||||
|
||||
@@ -103,7 +105,12 @@
|
||||
初期パスワードを<br> 変更します。
|
||||
</p>
|
||||
</a>
|
||||
</th>
|
||||
|
||||
</body>
|
||||
|
||||
<script>
|
||||
var admin =getElementByID
|
||||
</script>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user