Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package purluno.springrain.book
- import javax.annotation.Resource
- import org.springframework.stereotype.Controller
- import org.springframework.ui.Model
- import org.springframework.web.bind.annotation.RequestMapping
- import org.springframework.web.bind.annotation.RequestMethod
- import org.springframework.web.bind.annotation.RequestParam
- @Controller
- @RequestMapping("book")
- class BookController {
- @Resource
- BookService bookService
- /**
- * 책 등록/확인 기능의 시작점
- */
- @RequestMapping("")
- String index() {
- "book/index"
- }
- /**
- * 특정 ISBN에 해당하는 책 정보를 조회한다.
- */
- @RequestMapping("view")
- String view(Model model, @RequestParam String isbn) {
- def book = bookService.get(isbn)
- model.addAttribute("isbn", isbn)
- model.addAttribute("book", book)
- "book/view"
- }
- /**
- * 책 정보를 새로 등록하는 양식을 표시한다.
- */
- @RequestMapping(value = "add", method = RequestMethod.GET)
- String addGet(Model model, @RequestParam(defaultValue = "") String isbn) {
- model.addAttribute("isbn", isbn)
- "book/add"
- }
- /**
- * 양식으로 입력받은 책 정보를 저장한 후 조회 기능으로 이동한다.
- */
- @RequestMapping(value = "add", method = RequestMethod.POST)
- String addPost(Model model,
- @RequestParam String isbn,
- @RequestParam String title,
- @RequestParam String author,
- @RequestParam Integer year,
- @RequestParam String intro,
- @RequestParam String authorIntro) {
- bookService.save(isbn, title, author, year, intro, authorIntro)
- model.addAttribute("isbn", isbn)
- "redirect:/book/view"
- }
- /**
- * 책 정보 수정 양식을 표시한다.
- */
- @RequestMapping(value = "edit", method = RequestMethod.GET)
- String editGet(Model model, @RequestParam String isbn) {
- def book = bookService.get(isbn)
- model.addAttribute("book", book)
- "book/edit"
- }
- /**
- * 양식으로부터 책 정보 수정 내역을 입력받아 갱신한다.
- */
- @RequestMapping(value = "edit", method = RequestMethod.POST)
- String editPost(Model model,
- @RequestParam String isbn,
- @RequestParam String title,
- @RequestParam String author,
- @RequestParam Integer year,
- @RequestParam String intro,
- @RequestParam String authorIntro) {
- bookService.update(isbn, title, author, year, intro, authorIntro)
- model.addAttribute("isbn", isbn)
- "redirect:/book/view"
- }
- /**
- * 책 정보를 삭제한다.
- */
- @RequestMapping("delete")
- String delete(Model model, @RequestParam String isbn) {
- bookService.delete(isbn)
- "redirect:/book"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement