書籍登録コントローラ作成
This commit is contained in:
@@ -1,5 +1,60 @@
|
|||||||
package com.example.demo.controller;
|
package com.example.demo.controller;
|
||||||
|
|
||||||
public class AdminBookController {
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
|
||||||
|
import com.example.demo.form.BookForm;
|
||||||
|
import com.example.demo.service.BookAdminService;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class AdminBookController {
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(AdminBookController.class.getName());
|
||||||
|
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
|
||||||
|
|
||||||
|
HttpSession httpsession;
|
||||||
|
BookAdminService bookadmin;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public AdminBookController(HttpSession httpsession, BookAdminService bookadmin) {
|
||||||
|
this.httpsession = httpsession;
|
||||||
|
this.bookadmin = bookadmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
//書籍登録入力画面を表示する
|
||||||
|
@RequestMapping(value = "/bookRegistConfirm", method = { RequestMethod.GET, RequestMethod.POST })
|
||||||
|
public String showbookAdmin(Model model) {
|
||||||
|
try {
|
||||||
|
model.addAttribute("BookForm", new BookForm());
|
||||||
|
return "boolRegistConfirm";
|
||||||
|
} catch (Exception e) {
|
||||||
|
httpsession.invalidate();
|
||||||
|
e.printStackTrace();
|
||||||
|
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
|
||||||
|
return "/bookRegistInput";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//書籍登録を実行する
|
||||||
|
@PostMapping("/bookRegistComplete")
|
||||||
|
public String insertDepartmentResult(@ModelAttribute("BookForm") BookForm bookform, Model model) {
|
||||||
|
try {
|
||||||
|
bookadmin.register(bookform, null);
|
||||||
|
return "forward:/bookRegistComplete";
|
||||||
|
} catch (Exception e) {
|
||||||
|
httpsession.invalidate();
|
||||||
|
e.printStackTrace();
|
||||||
|
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
|
||||||
|
return "/bookRegistInput";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user