Advertisement
purluno

purluno.springrain.book.BookController

Apr 15th, 2014
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 2.58 KB | None | 0 0
  1. package purluno.springrain.book
  2.  
  3. import javax.annotation.Resource
  4.  
  5. import org.springframework.stereotype.Controller
  6. import org.springframework.ui.Model
  7. import org.springframework.web.bind.annotation.RequestMapping
  8. import org.springframework.web.bind.annotation.RequestMethod
  9. import org.springframework.web.bind.annotation.RequestParam
  10.  
  11. @Controller
  12. @RequestMapping("book")
  13. class BookController {
  14.     @Resource
  15.     BookService bookService
  16.  
  17.     /**
  18.      * 책 등록/확인 기능의 시작점
  19.      */
  20.     @RequestMapping("")
  21.     String index() {
  22.         "book/index"
  23.     }
  24.  
  25.     /**
  26.      * 특정 ISBN에 해당하는 책 정보를 조회한다.
  27.      */
  28.     @RequestMapping("view")
  29.     String view(Model model, @RequestParam String isbn) {
  30.         def book = bookService.get(isbn)
  31.         model.addAttribute("isbn", isbn)
  32.         model.addAttribute("book", book)
  33.         "book/view"
  34.     }
  35.  
  36.     /**
  37.      * 책 정보를 새로 등록하는 양식을 표시한다.
  38.      */
  39.     @RequestMapping(value = "add", method = RequestMethod.GET)
  40.     String addGet(Model model, @RequestParam(defaultValue = "") String isbn) {
  41.         model.addAttribute("isbn", isbn)
  42.         "book/add"
  43.     }
  44.  
  45.     /**
  46.      * 양식으로 입력받은 책 정보를 저장한 후 조회 기능으로 이동한다.
  47.      */
  48.     @RequestMapping(value = "add", method = RequestMethod.POST)
  49.     String addPost(Model model,
  50.                 @RequestParam String isbn,
  51.                 @RequestParam String title,
  52.                 @RequestParam String author,
  53.                 @RequestParam Integer year,
  54.                 @RequestParam String intro,
  55.                 @RequestParam String authorIntro) {
  56.         bookService.save(isbn, title, author, year, intro, authorIntro)
  57.         model.addAttribute("isbn", isbn)
  58.         "redirect:/book/view"
  59.     }
  60.  
  61.     /**
  62.      * 책 정보 수정 양식을 표시한다.
  63.      */
  64.     @RequestMapping(value = "edit", method = RequestMethod.GET)
  65.     String editGet(Model model, @RequestParam String isbn) {
  66.         def book = bookService.get(isbn)
  67.         model.addAttribute("book", book)
  68.         "book/edit"
  69.     }
  70.  
  71.     /**
  72.      * 양식으로부터 책 정보 수정 내역을 입력받아 갱신한다.
  73.      */
  74.     @RequestMapping(value = "edit", method = RequestMethod.POST)
  75.     String editPost(Model model,
  76.                 @RequestParam String isbn,
  77.                 @RequestParam String title,
  78.                 @RequestParam String author,
  79.                 @RequestParam Integer year,
  80.                 @RequestParam String intro,
  81.                 @RequestParam String authorIntro) {
  82.         bookService.update(isbn, title, author, year, intro, authorIntro)
  83.         model.addAttribute("isbn", isbn)
  84.         "redirect:/book/view"
  85.     }
  86.  
  87.     /**
  88.      * 책 정보를 삭제한다.
  89.      */
  90.     @RequestMapping("delete")
  91.     String delete(Model model, @RequestParam String isbn) {
  92.         bookService.delete(isbn)
  93.         "redirect:/book"
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement