`
sillycat
  • 浏览: 2539930 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Grails(2)Clinic Sample and Guide Book

 
阅读更多
Grails(2)Clinic Sample and Guide Book
Find the most recent sample from here:
https://github.com/grails-samples/grails-petclinic.git

>git clone https://github.com/grails-samples/grails-petclinic.git

Import the project into my STS, install the latest grails on MAC
>sudo port install grails

Follow the document and run the sample first
>grailsw run-app

Then I can visit the sample web page from this URL http://localhost:8080/petclinic.

I can also use my STS web container to run this web project. It is also working. I will go this project in details.

1. PetClinic Application Overview
It is built on already established Java technology like Spring & Hibernate.
Object Relational Mapping(ORM) on Hibernate
View technology called Groovy Server Pages(GSP)
Spring MVC and etc

H2 is the default database used by Grails.

PetClinic Application Design
Logging 
http://grails.org/doc/latest/guide/conf.html#logging
grails-app/Config.groovy

Business Layer
org.grails.samples.Speciality
org.grails.samples.PetType
org.grails.samples.Person
org.grails.samples.Vet
org.grails.samples.Owner
org.grails.samples.Pet
org.grails.samples.Visit

Logical Views & Implemented Use Cases
grails-app/views/clinic/index.gsp   home
grails-app/views/clinic/vets.gsp     vets and specialties
grails-app/views/owner/find.gsp
grails-app/views/owner/selection.gsp select the users from the same last name
grails-app/views/owner/show.gsp
grails-app/views/owner/add.gsp
grails-app/views/pet/add.gsp
grails-app/views/pet/addVisit.gsp
grails-app/views/common/_formField.gsp A template used to render common markup
grails-app/views/layouts/main.gsp   The layout used to include common CSS and markup

Testing  test the controller layer.

During reading the sample, here is for looking up http://grails.org/doc/latest/guide/index.html.

Make a sample project Dude Money Master

2. Getting Started
I successfully installed grails on my MAC and used the IDE STS.
>grails run-app
>grails test-app
>grails war

4. Configuration
4.1 Basic Configuration
grails-app/conf/BuildConfig.groovy
grails-app/conf/Config.groovy

The syntax is coming from the Grails-ConfigSlurper http://sillycat.iteye.com/blog/1567542.

The configuration has some benefits:
1. Can be merged
2. Can be written to disk
3. Convert to java properties, convert from java properties
4. the content can be structured
5. Can select the environment
     def config = new ConfigSlurper("development").parse(new File('Sample.groovy').toURL())
config =newConfigSlurper("test").parse(newFile('Sample.groovy').toURL())

BuildConfig.groovy is used for compile, doc and etc.
Config.groovy is for settings that are used when the application is running.

So the Config.groovy is packaged in war, BuildConfig.groovy is not.
foo.bar.hello = "world"
It is import to have the quotes. The property values can be any valid Groovy type, strings, integers, or arbitrary objects.

Some implicit variables can not be used:
userHome       home directory for the account that is running the grails
grailsHome    
appName        application name as it appears in application.properties
appVersion      version in application.properties

BuildConfig.groovy is only available from command script via grailsSettings.config

Config.groovy is via grailsApplication in controllers
def recipient = grailsApplication.config.foo.bar.hello

And it can be easily injected into services.
class MyService{
     def grailsApplication
     String greeting(){
          def recipient = grailsApplication.config.foo.bar.hello
          …snip...
     }
}

4.1.1 Built in options
Runtime Settings
grails.config.location    The location of properties files can be set to other class path or userHome place.
http://grails.org/doc/latest/guide/single.html#configExternalized

grails.war.dependencies Manage the jars in war.

4.1.2 Logging
The Basics
log4j setting in Config.groovy

Logging Levels
1. off
2. fatal
3. error
4. warn
5. info
6. debug
7. trace
8. all

Loggers
class MyClass {
     private static final log = LogFactory.getLog(this)
…snip…
}

The Root Logger
log4j = {
     appenders {
          file name: 'file', file:'/var/logs/mylog.log'
     }
     root{
          debug 'stdout', 'file'
     }
}

The root logger will log to 2 appenders. The default 'stdout' (console) apppender and file appender.

These are the default available appenders.
jdbc                JDBCAppender
console           ConsoleAppender
file                  FileAppender
rollingFile        RollingFileAppender

Environment-specific configuration
// other shared config
info "grails.app.controller"
environments {
     production {
          // Override previous setting for 'grails.app.controller'
          error "grails.app.controllers"
     }
}

4.1.3 GORM
grails.gorm.failOnError=true
grails.gorm.autoFlush=true

4.2 Environments
Per Environment Configuration
dataSource {
    pooled = false
    driverClassName = "org.h2.Driver"
    username = "sa"
    password = ""
}
environments {
    development {
        dataSource {
            dbCreate = "create-drop"
            url = "jdbc:h2:mem:devDb"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:h2:mem:testDb"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:h2:prodDb"
        }
    }
}Packaging and Running for Different Environments
>grails [envrionment] [command name]


references:
http://sillycat.iteye.com/blog/1567542
http://sillycat.iteye.com/blog/1074642
http://www.grails.org/tutorials?offset=0&max=10
https://github.com/grails-samples
http://grails.org/doc/latest/guide/index.html
http://grails.org/doc/latest/guide/conf.html

分享到:
评论

相关推荐

    the definitive guide to grails 2

    《Grails 2 的终极指南》是一本深入探讨Grails框架精髓的专业书籍,该书以英文撰写,旨在为读者提供全面、深入的Grails框架学习资料。Grails框架基于Groovy语言,是一种高度动态、敏捷的Java应用开发框架,它简化了...

    The definitive guide to grails 2 英文版 书 代码

    随书附带的代码库"The_definitive_guide_to_Grails2_code.zip"包含了书中示例项目的源代码,这有助于读者通过实际操作加深对理论知识的理解。读者可以按照书中的指导运行这些代码,跟随作者的脚步逐步学习Grails开发...

    [Grails] Grails 2 权威指南 (英文版)

    [Apress] The Definitive Guide to Grails 2 (E-Book) ☆ 出版信息:☆ [作者信息] Jeff Scott Brown, Graeme Rocher [出版机构] Apress [出版日期] 2013年01月23日 [图书页数] 360页 [图书语言] 英语 [图书...

    Grails Persistence with GORM and GSQL

    Grails Persistence with GORM and GSQL

    Grails A Quick-Start Guide:Dave Klein (DK)

    通过以上章节的总结,我们可以看到 Grails:A Quick-Start Guide 不仅涵盖了 Grails 的基础知识,还提供了实际项目开发的经验分享。无论是初学者还是有一定经验的开发者,都能从这本书中获得有价值的信息,帮助他们在...

    Grails 2 A Quick-Start Guide (Pragmatic Programmers 2013)

    ### Grails 2 快速入门指南核心知识点详解 #### 一、Grails框架简介与特点 Grails 是一个基于Groovy语言的全栈式的Java Web应用开发框架,它极大地简化了开发流程,并且能够快速地搭建出高性能的应用程序。本书...

    grails2

    grails-2

    The Definitive Guide to Grails 2nd Edition

    The Definitive Guide to Grails 2nd Edition.pdf

    The definitive guide to grails_2 源代码

    《The Definitive Guide to Grails 2》是关于Grails框架的一本权威指南,它为读者提供了深入理解和使用Grails 2开发Web应用程序所需的知识。Grails是一种基于Groovy语言的开源全栈式Web应用框架,它借鉴了Ruby on ...

    Grails : A Quick-Start Guide

    Java web development is notoriously tedious, ... This book will get you up and running with Grails by putting it to use in constructing an original, working application from start to finish. Book Details

    Grails.2.A.Quick-Start.Guide.pdf

    ### Grails 2: A Quick-Start Guide #### 书籍概览 《Grails 2:快速入门指南》是一本专为希望快速掌握Grails框架的开发者编写的实用指南。本书由Dave Klein与Ben Klein共同编写,通过一个逐步迭代的小项目来介绍...

    Grails Grails Grails

    2. **GORM(Grails Object Relational Mapping)**: GORM 是Grails的ORM框架,提供了与数据库交互的能力,支持关系型数据库,如MySQL、PostgreSQL等。它提供了CRUD操作,以及事务管理和动态查询。 3. **插件系统**...

Global site tag (gtag.js) - Google Analytics