|
|
|
|
@@ -18,47 +18,45 @@ import com.example.demo.service.BookInsertService;
|
|
|
|
|
@Controller
|
|
|
|
|
public class BookInsertController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private BookInsertService bookInsertService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private BookInsertService bookInsertService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private BookCategoryRepository categoryRepository;
|
|
|
|
|
@Autowired
|
|
|
|
|
private BookCategoryRepository categoryRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private SubCategoryRepository subCategoryRepository;
|
|
|
|
|
@Autowired
|
|
|
|
|
private SubCategoryRepository subCategoryRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private StorageLocationRepository storageLocationRepository;
|
|
|
|
|
@Autowired
|
|
|
|
|
private StorageLocationRepository storageLocationRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private BookInsertRepository bookInsertRepository;
|
|
|
|
|
@Autowired
|
|
|
|
|
private BookInsertRepository bookInsertRepository;
|
|
|
|
|
|
|
|
|
|
@GetMapping("/bookInsert")
|
|
|
|
|
public String bookInsert(Model model) {
|
|
|
|
|
model.addAttribute("nextBookManageId", bookInsertService.createBookManageId());
|
|
|
|
|
model.addAttribute("bookInsert", new BookInsert());
|
|
|
|
|
model.addAttribute("categoryList", categoryRepository.findAll());
|
|
|
|
|
model.addAttribute("subCategoryList", subCategoryRepository.findAll());
|
|
|
|
|
model.addAttribute("locationList", storageLocationRepository.findAll());
|
|
|
|
|
model.addAttribute("bookInsert", new BookInsert());
|
|
|
|
|
model.addAttribute("nextBookManageId",bookInsertService.createBookManageId());
|
|
|
|
|
model.addAttribute("bookInsert",new BookInsert());
|
|
|
|
|
model.addAttribute("categoryList",categoryRepository.findAll());
|
|
|
|
|
model.addAttribute("subCategoryList",subCategoryRepository.findAll());
|
|
|
|
|
model.addAttribute("locationList",storageLocationRepository.findAll());
|
|
|
|
|
model.addAttribute("bookInsert",new BookInsert());
|
|
|
|
|
return "bookInsert";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初期表示: 空の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()));
|
|
|
|
|
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()));
|
|
|
|
|
//そのカテゴリに属するサブカテゴリを持ってくる
|
|
|
|
|
} else {
|
|
|
|
|
model.addAttribute("subCategoryList", subCategoryRepository.findAll());
|
|
|
|
|
} else{
|
|
|
|
|
model.addAttribute("subCategoryList",subCategoryRepository.findAll());
|
|
|
|
|
}
|
|
|
|
|
model.addAttribute("locationList",storageLocationRepository.findAll());
|
|
|
|
|
model.addAttribute("bookInsert", bookInsert);
|
|
|
|
|
@@ -66,23 +64,32 @@ public class BookInsertController {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
bookInsertService.save(bookInsert);
|
|
|
|
|
model.addAttribute("bookInsert", bookInsert);
|
|
|
|
|
model.addAttribute("bookInsert",bookInsert);
|
|
|
|
|
return "bookInsertConfirm";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/bookInsert/category")
|
|
|
|
|
public String changeCategory(BookInsert bookInsert, Model model) {
|
|
|
|
|
//カテゴリプルダウンに表示するデータを取得
|
|
|
|
|
model.addAttribute("nextBookManageId", bookInsertService.createBookManageId());
|
|
|
|
|
model.addAttribute("categoryList", categoryRepository.findAll());
|
|
|
|
|
if (bookInsert.getBookCategoryId() != null) { //nullじゃなかったら
|
|
|
|
|
model.addAttribute("subCategoryList",
|
|
|
|
|
subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
|
|
|
|
|
//そのカテゴリに属するサブカテゴリを持ってくる
|
|
|
|
|
} else {
|
|
|
|
|
model.addAttribute("subCategoryList", subCategoryRepository.findAll());
|
|
|
|
|
//確認画面から「もどる」ボタンを押したら入力画面に戻る
|
|
|
|
|
@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("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()));
|
|
|
|
|
model.addAttribute("locationList",storageLocationRepository.findAll());
|
|
|
|
|
model.addAttribute("bookInsert", bookInsert);
|
|
|
|
|
|
|
|
|
|
return "bookInsert";
|
|
|
|
|
@@ -90,7 +97,13 @@ public class BookInsertController {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//画面で選択したカテゴリbookInsert.getBookCategoryId()に選択した結果をいれる
|
|
|
|
|
//subCategoryRepository.findBookCategory_BookCategoryId(bookInsert.getBookCategoryId(1)));
|
|
|
|
|
//「カテゴリIDが1のサブカテゴリを取ってくる」
|
|
|
|
|
//model.addAttribute("subCategoryList",取得結果)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//画面で選択したカテゴリbookInsert.getBookCategoryId()に選択した結果をいれる
|
|
|
|
|
//subCategoryRepository.findBookCategory_BookCategoryId(bookInsert.getBookCategoryId(1)));
|
|
|
|
|
//「カテゴリIDが1のサブカテゴリを取ってくる」
|
|
|
|
|
//model.addAttribute("subCategoryList",取得結果)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|