Korean Scaffolding

Last updated by admin 3 years ago

????(Scaffolding)

?????? ?????

????? ???? ??? ?????? ?? ??????? ?? ??? ? ????. ???? ???? ??? ??? ????:

  • ??? ??
  • ??/??/??/??(CRUD)? ???? ????

???? ?? ??

????? ???? ?? ??? ??? "scaffold" ??? ?? ????. "Book" ??? ???? ?? ????? ????? ????? "scaffold"?? ??? ??? ?? true? ???? ???:

class BookController {
   def scaffold = true
}
? ??? ???? ??? "BookController"? "Book" ??? ???? ?? ?? ??(naming convention)? ??? ?????. ?? ????? ?? ??? ???? ?? ????? ???? ???? "scaffold" ??? ?? ??? ???? ???? ???:
def scaffold = Author.class
?? ????! Grails ??????? ???? ??? ?? ??? ???? ????? ???. ?? ??? ???? ???? ?????:
  • list
  • show
  • edit
  • delete
  • create
  • save
  • update
?? ??? ? ?? ????? ?? ???? ?????:

??? ??? Java? ??? ?? ??? ????? ??? ??? ??? ??? ? ?? "scaffold" ??? ???? ????? ???.

?? ????

Grails? ???? ??? ?? ???? ???? ?? ??? ??? ??? ??? ????? ?? ??? ???? ?????? ??? ??? ??? ?? ????. ?? ?? ?? ????? ???? ??? changeAuthor ???? ?? ????? ?? ???? show ???? ?????? ?? ????:

class BookController {
   def scaffold = Book.class

def changeAuthor = { def b = Book.get( params["id"] ) b.author = Auhtor.get( params["author.id"] ) b.save()

// redirect to a scaffolded action redirect(action:show) } }

? ????? ?? ??? ???? ??? ?? ????:
class BookController {
   def scaffold = Book.class

// over rides scaffolded action to return both authors and books def list = { [ "books" : Book.list(), "authors": Author.list() ] } }

????? ? ????

???? ??? ?? ???? ??? ?? ????? ??? ?? ??? ??? ????. ??? ??? ??? Grails??? ????? ????? ?? ??? ???? ??? ?????. ????? ????? ????? ?? ??? ?????:

grails generate-controller
?? ????? ?? ??? ?????:
grails generate-views
? ? ????? ?? ??? ?????:
grails generate-all
?? ???? ?? ??? ???? ??? ?????? ??? ????. ?? ??? ???? Hibernate? ?? DB? ???? ??? ???? ???? ????? ?? ??? ? ????!

??? ?? ?????? ??

Grails? ?? ???? ?? ??? ????? ??? ? ????. ?? ?? ??? ??? ???? ??? ???? ??? constrains ???? ??? ??? ???? ?? ???:

def constraints = {
      title()
      releaseDate()
}
? "inList" ??? ???? ??? ??? ??? ??? ???? ??? ????? ? ?? ????:
def constraints = {
      title()
      category(inList:["Fiction", "Non-fiction", "Biography"])
      releaseDate()
}
?? ??? ???? range ??? ??? ?? ????:
def constraints = {
        age(range:18..65)
}
length ??? ???? ??? ???? ??? ? ?? ??? ??? ??? ?? ????:
def constraints = {
        name(length:0..30)
}
"widget" ??? ???? ??? ?? ?????? textarea ??? ?? ?? ????:
def constraints = {
        description(widget:'textarea')
}

??? ????

??? ??? Java? ???? ?? Hibernate? ???? ?? ???? ??? Grails? ???? ????? ??? ? ????. ? ??? ???? Grails? Hibernate ??? ??? ??? ?????? ?? GORM ? ?? ?? ???? ???????. ?? ??? ??, Hibernate? ??? ?? ??? ???? ?? ????? ??? ?? ?????? ?? ???? ?????? ?? ???:

import com.books.HibernateBook
class BookController {
     def scaffold = HibernateBook.class
}
? ???? ??? ????? ?? ?????? ?? ?????. ?, ??? ??? ??? ? ??? ??? ??? ?? ??? ????? ???.

Grails? ?? ????? ???? ?? ?????? ????? ??? ????? ????? ??? ??? ?? ??(naming convention)? ??? "Constaints"? ??? ??? Groovy ????? ?????. ?? ?? ??? ??? "HibernateBook" ???? ?? "com/books/HibernateBookConstraints.groovy" ????? HibernateBook ???? ?? ???? ?????. ???? ???? GORM?? ? ? ?? constraints? ????? ???. ? ? ??? ?? @Property? ?? ????:

constraints = {
      title(length:5..15)
      desc(blank:false)
}