????
????????????grails?????????????????????????????Grails??
?? ?Grails??????????target???????grails create-app
??target ???????????????????:
%PROJECT_HOME%
+ grails-app
+ conf ---> ??????????????
+ controllers ---> ?????
+ domain ---> ??????domain class?
+ i18n ---> ????i18n?????
+ services ---> ??????
+ taglib ---> ?????
+ util ---> ????????????/???????)
+ views ---> ??????
+ layouts ---> ??????
+ lib
+ spring ---> spring????????
+ src
+ groovy ---> ?????groovy???
+ java ---> ?????java???
+ hibernate ---> ??hibernate????
+ war
+ WEB-INF????? (??)
"create-app"??target ?"<..>/grails-app/conf"???????? Grails ??? . ?????????? :DevelopmentDataSource, TestDataSource, ??ProductionDataSource??????????grails??(????????????, ?????????????) ??????????:class DevelopmentDataSource {
boolean pooling = true
String dbCreate = "create-drop" // one of 'create', 'create-drop','update'
String url = "jdbc:hsqldb:mem:testDB"
String driverClassName = "org.hsqldb.jdbcDriver"
String username = "sa"
String password = ""
}?????????????driver????????????????????????????lib??????
??????Domain Class?
????????????? (?? "my-project)?????"grails create-domain-class" ??target ??????????????Book?. ?????????????????????????????????? (? GORM (Grails Object Relational Mapping)??????):class Book {
Long id
Long version String title
String author String toString() { "${this.class.name} : $id" } boolean equals(other) {
if(other?.is(this))return true
if(!(other instanceof Book)) return false if(!id || !other?.id || id!=other?.id) return false return true
} int hashCode() {
int hashCode = 0
hashCode = 29 * (hashCode + ( !id ? 0 : id ^ (id >>> 32) ) )
}
}???????????????, ???????????Grails????"<..>/grails-app/conf/ApplicationBootStrap.groovy"? "init" ??????
new Book(author:"Stephen King",title:"The Shining").save() new Book(author:"James Patterson",title:"Along Came a Spider").save()
??Controller ? Views
???Controllers ?Grails?????web?????????url?????????????closure??? "grails generate-all" ??target ????????????????????? "book" ???????? ????????????????????? Scaffolding????????.class BookController {
def scaffold = Book
}??Grails
?????Grails ????????grails run-app
?????jetty?????????8080?????????????????9090???????{{{}grails -Dserver.port=9090 run-app}}. ???book??????????????
http://localhost:8080/my-project/book/list
??list?BookController ??????????????????
http://localhost:8080/my-project/book



