- 浏览: 2486507 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Grails(4)Guide Book Chapter 4 Configuration and Command Line
4.7.2 Dependency Repositories
Remote Repositories
Initially your BuildConfig.groovy does not use any remote public Maven repositories. There is a default grailsHome() repository that will locate the JAR files Grails needs from my Grails installation. To configure a public repository, specify it in repositories block:
repositories {
mavenCentral() //maven center
ebr() //spring source enterprise bundle repository
}
we can also specify a specific URL
repositories{
mavenRepo name: "Codehaus", root: "http://repository.codehaus.org"
}
Controlling Repositories Inherited from Plugins
There is a flag for inherit
repositories{
inherit false
}
Offline Mode
There are times when it is not desirable to connect to any remote repositories(whilst working on the train for example)
>grails --offline run-app
Or do that in BuildConfig.groovy file:
grails.offline.mode=true
Local Resolvers
repositories {
flatDir name: 'myRepo', dirs: '/path/to/repo'
}
To specify my local Maven cache (~/.m2/repository) as a repository:
repositories {
mavenLocal()
}
Custom Resolvers
org.apache.ivy.plugins.resolver.URLResolver()
org.apache.ivy.plugins.resolver.SshResolver
Authentication
This can be placed in USER_HOME/.grails/settings.groovy file
grails.project.ivy.authentication = {
credentials {
realm = ".."
host = "localhost"
username = "user"
password = "111111"
}
}
4.7.3 Debugging Resolution
4.7.5 Providing Default Dependencies
Sometimes, the jar files will be provided by the container.
grails.project.dependency.resolution = {
defaultDependenciesProvided true // all of the default dependencies will
// be 'provided' by the container
…snip...
}
4.7.7 Dependency Reports
4.7.9 Maven Integration
grails.project.dependency.resolution = {
pom true
...
}
The line pom true tells Grails to parse Maven's pom.xml and load dependencies from there.
4.7.10 Deploying to a Maven Repository
>grails maven-install
>grails maven-deploy
4.7.11 Plugin Dependencies
grails.project.dependency.resolution = {
…
repositories {
}
plugins {
runtime ':hibernate:1.2.1'
}
dependencies{
}
}
Plugin Exclusions
plugins {
runtime(':weceem:0.8'){
excludes "searchable" //excludes most recent version
}
runtime ':searchable:0.5.4' //specifies a fixed searchable version
}
5. The Command Line
Grails' command line system is built on Gant - a simple Groovy wrapper around Apache ant.
Grails searches in the following directories for Gant scripts to execute:
USER_HOME/.gails/scripts
PROJECT_HOME/scripts
PROJECT_HOME/plugins/*/scripts
GRAILS_HOME/scripts
Grails will also convert command names that are in lower case.
>grails run-app
This command will look for RunApp.groovy.
From my understanding, seldom, we need some configuration.
>export GRAILS_OPTS="-Xmx1G -Xms256m -XX:MaxPermSize=256m"
>grails run-app
5.1 Interactive Mode
>grails
Enter interactive mode, then we can get a lot of help when we type tab button.
grails>
If we want to run an external process whilst interactive mode is running. We can do so by starting the command with !
grails>!ls
that will list all the file under this directory.
!ls !pwd some commands are working, for example, !cd is not working.
5.2 Forked Tomcat Execution
Grails 2.2 and above
5.3 Creating Gant Scripts
We can create our own Gant scripts by running the create-script command.
>grails create-script compile-sources
That will create a script called scripts/CompileSources.groovy
5.4 Re-using Grails scripts
includeTargets << grailsScript("_GrailsBootstrap")
includeTarget << new File("/path/to/my/own/script.groovy")
5.5 Hooking into Events
Event handlers are defined in scripts called _Events.groovy
5.6 Customizing the build
5.7 Ant and Maven
Ant Integration
>grails integrate-with --ant
Maven Integration
If my project named hellosillycat
>cd hellosillycat
>grails create-pom com.sillycat
5.8 Grails Wrapper
Generating The Wrapper
build the project with install grails
>grails wrapper
Using The Wrapper
./grailsw create-domain-class com.sillycat.Person
./grailsw run-app
6. Object Relational Mapping(GORM)
6.1 Quick Start Guide
A domain class can be created with the create-domain-class command
>grails create-domain-class hello world.Person
We can customize the class by adding properties:
class Person {
String name
Integer age
Date lastVist
}
6.1.1 Basic CRUD(Create/Read/Update/Delete)
Create
def p = new Person(name: "Carl", age: 30, lastVisit: new Date())
p.save()
Read
def p = Person.get(1)
assert 1 == p.id
Grails transparently adds an implicit id property to your domain class which you can use for retrieval.
We can also read the Person object back from the database
def p = Person.read(1)
This incurs no database access until a method other than getId(0 is called. That is to say, lazy load
def p = Person.load(1)
Update
Update some properties, then call save method
def p = Person.get(1)
p.name = "Kiko"
p.save()
Delete
def p = Person.get(1)
p.delete()
6.2 Domain Modeling in GORM
6.2.1 Association in GORM
6.2.1.1 Many-to-one and one-to-one
6.2.1.2 One-to-many
class Author {
static hasMany = [Books: Book]
String name
}
class Book {
static belongsTo = [author: Author]
String title
}
6.2.1.3 Many-to-many
class Book{
static belongsTo = Author
static hasMany = [authors:Author]
String title
}
class Author{
static hasMany = [books:Book]
String name
}
6.2.4 Sets, Lists and Maps
Sets of Objects
static hasMany = [books: Book]
It is a java.util.Set. Sets guarantee uniqueness but not order.
If we need order, we need to implement java.lang.Comparable. And define SortedSet
class Author {
SortedSet books
static hasMany = [books: Book]
}
class Book implements Comparable {
String title
Date releaseDate = new Date()
int compareTo(obj) {
releaseDate.compareTo(obj.releaseDate)
}
}
Lists of Objects
class Author {
List books
static hasMany = [books: Book]
}
Bags of Objects
class Author {
Collection books
static hasMany = [books: Book]
}
Maps of Objects
class Author {
Map books
}
def a = new Author()
a.books = ["key number“: "book name"]
References:
http://grails.org/doc/latest/guide/conf.html#dependencyRepositories
http://grails.org/doc/latest/guide/index.html
http://grails.org/doc/latest/guide/commandLine.html
http://grails.org/doc/latest/guide/GORM.html
4.7.2 Dependency Repositories
Remote Repositories
Initially your BuildConfig.groovy does not use any remote public Maven repositories. There is a default grailsHome() repository that will locate the JAR files Grails needs from my Grails installation. To configure a public repository, specify it in repositories block:
repositories {
mavenCentral() //maven center
ebr() //spring source enterprise bundle repository
}
we can also specify a specific URL
repositories{
mavenRepo name: "Codehaus", root: "http://repository.codehaus.org"
}
Controlling Repositories Inherited from Plugins
There is a flag for inherit
repositories{
inherit false
}
Offline Mode
There are times when it is not desirable to connect to any remote repositories(whilst working on the train for example)
>grails --offline run-app
Or do that in BuildConfig.groovy file:
grails.offline.mode=true
Local Resolvers
repositories {
flatDir name: 'myRepo', dirs: '/path/to/repo'
}
To specify my local Maven cache (~/.m2/repository) as a repository:
repositories {
mavenLocal()
}
Custom Resolvers
org.apache.ivy.plugins.resolver.URLResolver()
org.apache.ivy.plugins.resolver.SshResolver
Authentication
This can be placed in USER_HOME/.grails/settings.groovy file
grails.project.ivy.authentication = {
credentials {
realm = ".."
host = "localhost"
username = "user"
password = "111111"
}
}
4.7.3 Debugging Resolution
4.7.5 Providing Default Dependencies
Sometimes, the jar files will be provided by the container.
grails.project.dependency.resolution = {
defaultDependenciesProvided true // all of the default dependencies will
// be 'provided' by the container
…snip...
}
4.7.7 Dependency Reports
4.7.9 Maven Integration
grails.project.dependency.resolution = {
pom true
...
}
The line pom true tells Grails to parse Maven's pom.xml and load dependencies from there.
4.7.10 Deploying to a Maven Repository
>grails maven-install
>grails maven-deploy
4.7.11 Plugin Dependencies
grails.project.dependency.resolution = {
…
repositories {
}
plugins {
runtime ':hibernate:1.2.1'
}
dependencies{
}
}
Plugin Exclusions
plugins {
runtime(':weceem:0.8'){
excludes "searchable" //excludes most recent version
}
runtime ':searchable:0.5.4' //specifies a fixed searchable version
}
5. The Command Line
Grails' command line system is built on Gant - a simple Groovy wrapper around Apache ant.
Grails searches in the following directories for Gant scripts to execute:
USER_HOME/.gails/scripts
PROJECT_HOME/scripts
PROJECT_HOME/plugins/*/scripts
GRAILS_HOME/scripts
Grails will also convert command names that are in lower case.
>grails run-app
This command will look for RunApp.groovy.
From my understanding, seldom, we need some configuration.
>export GRAILS_OPTS="-Xmx1G -Xms256m -XX:MaxPermSize=256m"
>grails run-app
5.1 Interactive Mode
>grails
Enter interactive mode, then we can get a lot of help when we type tab button.
grails>
If we want to run an external process whilst interactive mode is running. We can do so by starting the command with !
grails>!ls
that will list all the file under this directory.
!ls !pwd some commands are working, for example, !cd is not working.
5.2 Forked Tomcat Execution
Grails 2.2 and above
5.3 Creating Gant Scripts
We can create our own Gant scripts by running the create-script command.
>grails create-script compile-sources
That will create a script called scripts/CompileSources.groovy
5.4 Re-using Grails scripts
includeTargets << grailsScript("_GrailsBootstrap")
includeTarget << new File("/path/to/my/own/script.groovy")
5.5 Hooking into Events
Event handlers are defined in scripts called _Events.groovy
5.6 Customizing the build
5.7 Ant and Maven
Ant Integration
>grails integrate-with --ant
Maven Integration
If my project named hellosillycat
>cd hellosillycat
>grails create-pom com.sillycat
5.8 Grails Wrapper
Generating The Wrapper
build the project with install grails
>grails wrapper
Using The Wrapper
./grailsw create-domain-class com.sillycat.Person
./grailsw run-app
6. Object Relational Mapping(GORM)
6.1 Quick Start Guide
A domain class can be created with the create-domain-class command
>grails create-domain-class hello world.Person
We can customize the class by adding properties:
class Person {
String name
Integer age
Date lastVist
}
6.1.1 Basic CRUD(Create/Read/Update/Delete)
Create
def p = new Person(name: "Carl", age: 30, lastVisit: new Date())
p.save()
Read
def p = Person.get(1)
assert 1 == p.id
Grails transparently adds an implicit id property to your domain class which you can use for retrieval.
We can also read the Person object back from the database
def p = Person.read(1)
This incurs no database access until a method other than getId(0 is called. That is to say, lazy load
def p = Person.load(1)
Update
Update some properties, then call save method
def p = Person.get(1)
p.name = "Kiko"
p.save()
Delete
def p = Person.get(1)
p.delete()
6.2 Domain Modeling in GORM
6.2.1 Association in GORM
6.2.1.1 Many-to-one and one-to-one
6.2.1.2 One-to-many
class Author {
static hasMany = [Books: Book]
String name
}
class Book {
static belongsTo = [author: Author]
String title
}
6.2.1.3 Many-to-many
class Book{
static belongsTo = Author
static hasMany = [authors:Author]
String title
}
class Author{
static hasMany = [books:Book]
String name
}
6.2.4 Sets, Lists and Maps
Sets of Objects
static hasMany = [books: Book]
It is a java.util.Set. Sets guarantee uniqueness but not order.
If we need order, we need to implement java.lang.Comparable. And define SortedSet
class Author {
SortedSet books
static hasMany = [books: Book]
}
class Book implements Comparable {
String title
Date releaseDate = new Date()
int compareTo(obj) {
releaseDate.compareTo(obj.releaseDate)
}
}
Lists of Objects
class Author {
List books
static hasMany = [books: Book]
}
Bags of Objects
class Author {
Collection books
static hasMany = [books: Book]
}
Maps of Objects
class Author {
Map books
}
def a = new Author()
a.books = ["key number“: "book name"]
References:
http://grails.org/doc/latest/guide/conf.html#dependencyRepositories
http://grails.org/doc/latest/guide/index.html
http://grails.org/doc/latest/guide/commandLine.html
http://grails.org/doc/latest/guide/GORM.html
发表评论
-
NodeJS12 and Zlib
2020-04-01 07:44 430NodeJS12 and Zlib It works as ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 291Traefik 2020(1)Introduction and ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 373Private Registry 2020(1)No auth ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 334Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 415NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 359Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 291Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 207GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 390GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 274GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 263Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 259Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 251Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 235Serverless with NodeJS and Tenc ... -
NodeJS MySQL Library and npmjs
2020-02-07 06:21 233NodeJS MySQL Library and npmjs ... -
Python Library 2019(1)requests and aiohttp
2019-12-18 01:12 225Python Library 2019(1)requests ... -
NodeJS Installation 2019
2019-10-20 02:57 517NodeJS Installation 2019 Insta ... -
Monitor Tool 2019(2)Monit on Multiple Instances and Email Alerts
2019-10-18 10:57 229Monitor Tool 2019(2)Monit on Mu ... -
Sqlite Database 2019(1)Sqlite3 Installation and Docker phpsqliteadmin
2019-09-05 11:24 319Sqlite Database 2019(1)Sqlite3 ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 320Supervisor 2019(2)Ubuntu and Mu ...
相关推荐
详细介绍grails框架的奥秘,英文版你值得拥有
The definitive guide to grails 2 英文版 书和随书代码, 学习grails必备
Grails is a full stack web development framework that enables you to build complete web applications in a fraction of the time and with less code than other frameworks. In Grails: A Quick-Start Guide...
Using the principle of convention-over-configuration and the dynamic Groovy programming language, Grails takes the pain out of web development and brings back the fun. This book will get you up and ...
Grails Grails Grails Grails Grails
Groovy / Grails F4 The Best Web Server
Groovy and Grails Recipes 作者:Bashar Abdul-Jawad 共407页 PART 1 Groovy by Example CHAPTER 1 Getting Started with Groovy CHAPTER 2 From Java to Groovy CHAPTER 3 Groovy Data Types and Control ...
First-time developers are amazed at how quickly you can get a page-centric MVC web site up and running thanks to the scaffolding and convention over configuration that Grails provides. Advanced web ...
去年早些时候写的一个项目驱动的grails入门教程。绝对原创。
grails1.0开发框架4 类似于ruby on rails的框架。
the best of the best. written by one of core author of grails team. Highly recommended.
Definitive Guide to Grails
Grails权威指南Grails权威指南Grails权威指南Grails权威指南Grails权威指南Grails权威指南
begining groovy and grails
Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright...
grails-4.0.4.zip
The Definitive Guide to Grails 2nd Edition.pdf
Grails设计者的作品,经典的Grails学习资料
The definitive guide to grails_2 随书 源代码