Last updated by admin 3 years ago
????(Scaffolding)
?????? ?????
????? ???? ??? ?????? ?? ??????? ?? ??? ? ????. ???? ???? ??? ??? ????:???? ?? ??
????? ???? ?? ??? ??? "scaffold" ??? ?? ????. "Book" ??? ???? ?? ????? ????? ????? "scaffold"?? ??? ??? ?? true? ???? ???:class BookController {
def scaffold = true
}def scaffold = Author.class
- list
- show
- edit
- delete
- create
- save
- update
?? ????
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
??? ?? ?????? ??
Grails? ?? ???? ?? ??? ????? ??? ? ????. ?? ?? ??? ??? ???? ??? ???? ??? constrains ???? ??? ??? ???? ?? ???:def constraints = {
title()
releaseDate()
}def constraints = {
title()
category(inList:["Fiction", "Non-fiction", "Biography"])
releaseDate()
}def constraints = {
age(range:18..65)
}def constraints = {
name(length:0..30)
}def constraints = {
description(widget:'textarea')
}??? ????
??? ??? Java? ???? ?? Hibernate? ???? ?? ???? ??? Grails? ???? ????? ??? ? ????. ? ??? ???? Grails? Hibernate ??? ??? ??? ?????? ?? GORM ? ?? ?? ???? ???????. ?? ??? ??, Hibernate? ??? ?? ??? ???? ?? ????? ??? ?? ?????? ?? ???? ?????? ?? ???:import com.books.HibernateBook
class BookController {
def scaffold = HibernateBook.class
}constraints = {
title(length:5..15)
desc(blank:false)
}


