[edit]バグ修正をしました
This commit is contained in:
@@ -18,45 +18,47 @@ 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);
|
||||
@@ -64,32 +66,23 @@ private BookInsertRepository bookInsertRepository;
|
||||
|
||||
}
|
||||
bookInsertService.save(bookInsert);
|
||||
model.addAttribute("bookInsert",bookInsert);
|
||||
model.addAttribute("bookInsert", bookInsert);
|
||||
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) {
|
||||
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("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());
|
||||
}
|
||||
model.addAttribute("locationList", storageLocationRepository.findAll());
|
||||
model.addAttribute("bookInsert", bookInsert);
|
||||
|
||||
return "bookInsert";
|
||||
@@ -97,13 +90,7 @@ private BookInsertRepository bookInsertRepository;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//画面で選択したカテゴリ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",取得結果)
|
||||
|
||||
Reference in New Issue
Block a user