Thai Quick Start

Last updated by admin 4 years ago

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

???????????? Grails

????????????????? Grails ???? ???????????? target ??????????????????????????????????????????????:

grails create-app
??? target ????????????????????????????????? ?????????????????????????????????????????????:
%PROJECT_HOME%
    + grails-app
       + conf                 ---> ????????????????? artifacts ???????????????? ???? data sources
       + controllers          ---> ????????????????? controller artifacts
       + domain               ---> ????????????????? domain classes
       + i18n                 ---> ?????????????????????????????????????? i18n
       + services             ---> ????????????????? services
       + taglib               ---> ????????????????? tag libraries
       + views                ---> ????????????????? views
           + layouts          ---> ????????????????? layouts
   + lib
   + spring                   ---> ?????????????????????? spring (?????????)
   + hibernate                ---> ?????????????????????? hibernate (?????????)
   + war
       + WEB-INF

??????????????????? (Data Source) (?????????)

??? target "create-app" ???????????????? (??????????? artifacts) ????????????????? Grails ??????????????????? "<..>/grails-app/conf" ????????????????????????????? HSQLDB ??? in-memory (???????????????? ????????????????????????????????????????) ?????????????????????????????????????????:

class ApplicationDataSource {
   @Property String url = "jdbc:hsqldb:mem:testDB"
   @Property String driverClassName = "org.hsqldb.jdbcDriver"
   @Property String username = "sa"
   @Property String password = ""
}
????????????????????????????????????? ? ??????????????????????????????????????????????????????????????????? jar ???????????????????????????????? <..>/lib

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

??????????????????????????????????????????????? (???????????? "my-project") ???????? "cd my-project" ??????? target "grails create-domain-class" ????????????????????????????????????? ??????????????? artifact ??? persistent ?????????? properties ?????????????????????????????????? (????????????????????????????????????? GORM (Grails Object Relational Mapping) ):

class Book {
    @Property Long id
    @Property Long version

@Property String title @Property String author }

????????????????????????????????????????????? ????????????????????????????????????????????????? closure "init" ??????????????????????????? (application bootstrap) ??? Grails ????????????????? "<..>/grails-app/conf":
new Book(author:"Stephen King",title:"The Shining").save()
new Book(author:"James Patterson",title:"Along Came a Spider").save()

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

????????????? controller ???????????????? Grails ???????????? ?????????????????????????????? (web request) ??? URL ???????????????????????????????????????????????? closure ????????????????? ??

??? target "grails generate-all" ?????????????????????????????? ?????????????????? "book" ???????? Grails ?????????????????????????????????????????????????????? CRUD ??????? ???????????.

????? Grails

???????????????????????????????? Grails ???????????? ?????? target ????????

grails run-app
?????????????????????????????? Jetty servlet engine ????????????? 8080 ??????????????????????????????????? 9090 ???????????? {{grails -Dserver.port=9090 run-app}} ??????????????????????????????????????????????????????????????????????????????????:
http://localhost:8080/my-project/book/list

??????? closure "list" ???? action ???????????? BookController ???????????????????????:

http://localhost:8080/my-project/book
&nbsp;