The Grails Framework
Table of contents
1
Introduction
2
Getting Started
3
Upgrading from Grails 3.3.x
4
Configuration
5
The Command Line
6
Application Profiles
7
Object Relational Mapping (GORM)
8
The Web Layer
9
Traits
10
REST
11
Asynchronous Programming
12
Validation
13
The Service Layer
14
Static Type Checking And Compilation
15
Testing
16
Internationalization
17
Security
18
Plugins
19
Grails and Spring
20
Scaffolding
21
Deployment
22
Contributing to Grails
Quick Reference
(
Quick Reference
)
The Grails Framework
Authors:
The Grails Team
Version:
4.1.0
Table of Contents
1
Introduction
1.1
What's new in Grails 4?
1.1.1
Updated Dependencies
1.1.2
Micronaut Parent Context
2
Getting Started
2.1
Installation Requirements
2.2
Downloading and Installing
2.3
Creating an Application
2.4
A Hello World Example
2.5
Using Interactive Mode
2.6
Getting Set Up in an IDE
2.7
Convention over Configuration
2.8
Running and Debugging an Application
2.9
Testing an Application
2.10
Deploying an Application
2.11
Supported Java EE Containers
2.12
Creating Artefacts
2.13
Generating an Application
3
Upgrading from Grails 3.3.x
4
Configuration
4.1
Basic Configuration
4.1.1
Options for the YML format Config
4.1.2
Built in options
4.1.3
Logging
4.1.3.1
Logger Names
4.1.3.2
Masking Request Parameters From Stacktrace Logs
4.1.3.3
External Configuration File
4.1.4
GORM
4.1.5
Configuring an HTTP proxy
4.2
The Application Class
4.2.1
Executing the Application Class
4.2.2
Customizing the Application Class
4.2.3
The Application LifeCycle
4.3
Environments
4.4
The DataSource
4.4.1
DataSources and Environments
4.4.2
Automatic Database Migration
4.4.3
Transaction-aware DataSource Proxy
4.4.4
Database Console
4.4.5
Multiple Datasources
4.5
Versioning
4.6
Dependency Resolution
5
The Command Line
5.1
Interactive Mode
5.2
Creating Custom Scripts
5.3
Creating Custom Commands
5.4
Re-using Grails scripts
5.5
Building with Gradle
5.5.1
Defining Dependencies with Gradle
5.5.2
Working with Gradle Tasks
5.5.3
Grails plugins for Gradle
6
Application Profiles
6.1
Creating Profiles
6.2
Profile Inheritance
6.3
Publishing Profiles
6.4
Understanding Profiles
6.5
Creating Profile Commands
6.6
Creating Profile Features
7
Object Relational Mapping (GORM)
7.1
Quick Start Guide
7.1.1
Basic CRUD
7.2
Further Reading on GORM
8
The Web Layer
8.1
Controllers
8.1.1
Understanding Controllers and Actions
8.1.2
Controllers and Scopes
8.1.3
Models and Views
8.1.4
Redirects and Chaining
8.1.5
Data Binding
8.1.6
Responding with JSON
8.1.7
More on JSONBuilder
8.1.8
Responding with XML
8.1.9
Uploading Files
8.1.10
Command Objects
8.1.11
Handling Duplicate Form Submissions
8.1.12
Simple Type Converters
8.1.13
Declarative Controller Exception Handling
8.2
Groovy Server Pages
8.3
URL Mappings
8.3.1
Mapping to Controllers and Actions
8.3.2
Mapping to REST resources
8.3.3
Redirects In URL Mappings
8.3.4
Embedded Variables
8.3.5
Mapping to Views
8.3.6
Mapping to Response Codes
8.3.7
Mapping to HTTP methods
8.3.8
Mapping Wildcards
8.3.9
Automatic Link Re-Writing
8.3.10
Applying Constraints
8.3.11
Named URL Mappings
8.3.12
Customizing URL Formats
8.3.13
Namespaced Controllers
8.4
CORS
8.5
Interceptors
8.5.1
Defining Interceptors
8.5.2
Matching Requests with Interceptors
8.5.3
Ordering Interceptor Execution
8.6
Content Negotiation
9
Traits
9.1
Traits Provided by Grails
9.1.1
WebAttributes Trait Example
10
REST
10.1
Domain classes as REST resources
10.2
Mapping to REST resources
10.3
Linking to REST resources from GSP pages
10.4
Versioning REST resources
10.5
Implementing REST controllers
10.5.1
Extending the RestfulController super class
10.5.2
Implementing REST Controllers Step by Step
10.5.3
Generating a REST controller using scaffolding
10.6
Calling REST Services with HttpClient
10.7
The REST Profile
10.8
The AngularJS Profile
10.9
The Angular Profile
10.10
JSON Views
10.10.1
Getting Started
10.10.2
Creating JSON Views
10.10.3
JSON View Templates
10.10.4
Rendering Domain Classes with JSON Views
10.10.5
JSON Views by Convention
10.11
Customizing Response Rendering
10.11.1
Customizing the Default Renderers
10.11.2
Implementing a Custom Renderer
10.11.3
Using GSP to Customize Rendering
10.12
Hypermedia as the Engine of Application State
10.12.1
HAL Support
10.12.2
Atom Support
10.12.3
Vnd.Error Support
10.13
Customizing Binding of Resources
10.14
RSS and Atom
11
Asynchronous Programming
12
Validation
12.1
Declaring Constraints
12.2
Validating Constraints
12.3
Sharing Constraints Between Classes
12.4
Validation on the Client
12.5
Validation and Internationalization
12.6
Applying Validation to Other Classes
13
The Service Layer
13.1
Declarative Transactions
13.1.1
Transactions and Multi-DataSources
13.1.2
Transactions Rollback and the Session
13.2
Scoped Services
13.3
Dependency Injection and Services
14
Static Type Checking And Compilation
14.1
The GrailsCompileStatic Annotation
14.2
The GrailsTypeChecked Annotation
15
Testing
15.1
Unit Testing
15.2
Integration Testing
15.3
Functional Testing
16
Internationalization
16.1
Understanding Message Bundles
16.2
Changing Locales
16.3
Reading Messages
16.4
Scaffolding and i18n
17
Security
17.1
Securing Against Attacks
17.2
Cross Site Scripting (XSS) Prevention
17.3
Encoding and Decoding Objects
17.4
Authentication
17.5
Security Plugins
17.5.1
Spring Security
18
Plugins
18.1
Creating and Installing Plugins
18.2
Plugin Repositories
18.3
Providing Basic Artefacts
18.4
Evaluating Conventions
18.5
Hooking into Runtime Configuration
18.6
Adding Methods at Compile Time
18.7
Adding Dynamic Methods at Runtime
18.8
Participating in Auto Reload Events
18.9
Understanding Plugin Load Order
18.10
The Artefact API
18.10.1
Asking About Available Artefacts
18.10.2
Adding Your Own Artefact Types
19
Grails and Spring
19.1
Configuring Additional Beans
19.2
Runtime Spring with the Beans DSL
19.3
The BeanBuilder DSL Explained
19.4
Property Placeholder Configuration
19.5
Property Override Configuration
19.6
Spring Boot Actuators
20
Scaffolding
21
Deployment
21.1
Standalone
21.2
Container Deployment (e.g. Tomcat)
21.3
Deployment Configuration Tasks
22
Contributing to Grails
22.1
Report Issues in Github's issue tracker
22.2
Build From Source and Run Tests
22.3
Submit Patches to Grails Core
22.4
Submit Patches to Grails Documentation
Quick Reference
(
hide
)
Command Line
Usage
bug-report
clean
compile
console
create-app
create-command
create-controller
create-domain-class
create-functional-test
create-hibernate-cfg-xml
create-integration-test
create-interceptor
create-plugin
create-profile
create-script
create-service
create-taglib
create-unit-test
dependency-report
docs
generate-all
generate-controller
generate-views
help
install-templates
list-plugins
list-profiles
package-plugin
package
plugin-info
profile-info
run-app
run-command
run-script
schema-export
shell
stats
stop-app
test-app
war
Constraints
Usage
attributes
bindable
blank
creditCard
email
inList
matches
max
maxSize
min
minSize
notEqual
nullable
range
scale
size
unique
url
validator
widget
Controllers
Usage
actionName
allowedMethods
bindData
chain
controllerName
defaultAction
errors
flash
forward
grailsApplication
hasErrors
header
namespace
params
redirect
render
request
respond
response
responseFormats
scope
servletContext
session
withForm
withFormat
Database Mapping
Usage
autoImport
autoTimestamp
batchSize
cache
cascade
column
comment
discriminator
dynamicInsert
dynamicUpdate
fetch
id
ignoreNotFound
indexColumn
insertable
joinTable
lazy
order
sort
table
type
updateable
version
Domain Classes
Usage
addTo
attach
belongsTo
clearErrors
constraints
count
countBy
createCriteria
delete
discard
embedded
errors
executeQuery
executeUpdate
exists
fetchMode
find
findAll
findAllBy
findAllWhere
findBy
findOrCreateBy
findOrCreateWhere
findOrSaveBy
findOrSaveWhere
findWhere
first
get
getAll
getDirtyPropertyNames
getPersistentValue
hasErrors
hasMany
hasOne
ident
instanceOf
isAttached
isDirty
last
list
listOrderBy
load
lock
mapWith
mappedBy
mapping
merge
namedQueries
properties
read
refresh
removeFrom
save
transients
validate
where
whereAny
withCriteria
withNewSession
withSession
withTransaction
Plug-ins
Usage
URL mappings
codecs
controllers
core
dataSource
domainClasses
hibernate
i18n
logging
scaffolding
services
servlets
Services
Usage
scope
transactional
Servlet API
request
response
servletContext
session