You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
static scaffold = Book // Or any other domain class such as "Author", "Publisher"
46
47
}
47
48
----
48
49
@@ -58,45 +59,115 @@ With this configured, when you start your application the actions and views will
58
59
59
60
A CRUD interface will also be generated. To access this open `http://localhost:8080/book` in a browser.
60
61
61
-
Note: The old alternative of defining `scaffold` property:
62
+
If you prefer to keep your domain model in Java and https://hibernate.org/[mapped with Hibernate] you can still use scaffolding, simply import the domain class and use it in the `@Scaffold` annotation.
63
+
64
+
===== Legacy Static Scaffold Property
65
+
66
+
The older `static scaffold = Book` syntax is still supported but the `@Scaffold` annotation is preferred:
67
+
68
+
[source,groovy]
69
+
----
70
+
class BookController {
71
+
static scaffold = Book // Legacy syntax - @Scaffold annotation is preferred
72
+
}
73
+
----
74
+
75
+
NOTE: The `static scaffold = true` form is not supported in Grails 3.0 and above.
76
+
77
+
===== Scaffolded Services
78
+
79
+
In addition to controllers, you can also scaffold services using the `@Scaffold` annotation:
This controller will automatically locate and use the corresponding `BookService` for all data operations.
71
113
72
-
If you prefer to keep your domain model in Java and https://hibernate.org/[mapped with Hibernate] you can still use scaffolding, simply import the domain class and set its name as the `scaffold` argument.
114
+
===== Extending Custom Classes
73
115
74
-
You can add new actions to a scaffolded controller, for example:
116
+
You can specify a custom class to extend for your scaffolded controllers or services:
// overrides scaffolded action to return both authors and books
102
173
def index() {
@@ -108,7 +179,7 @@ class BookController {
108
179
def show() {
109
180
def book = Book.get(params.id)
110
181
log.error("{}", book)
111
-
[bookInstance: book]
182
+
[bookInstance: book]
112
183
}
113
184
}
114
185
----
@@ -122,35 +193,96 @@ Also, the standard scaffold views expect model variables of the form `<propertyN
122
193
123
194
==== Static Scaffolding
124
195
196
+
Grails lets you generate a controller and the views used to create the above interface from the command line.
125
197
126
-
Grails lets you generate a controller and the views used to create the above interface from the command line. To generate a controller type:
198
+
===== Generating Controllers and Views
127
199
128
-
[source,groovy]
200
+
To generate a controller type:
201
+
202
+
[source,bash]
129
203
----
130
204
grails generate-controller Book
131
205
----
132
206
133
207
or to generate the views:
134
208
135
-
[source,groovy]
209
+
[source,bash]
136
210
----
137
211
grails generate-views Book
138
212
----
139
213
140
214
or to generate everything:
141
215
142
-
[source,groovy]
216
+
[source,bash]
143
217
----
144
218
grails generate-all Book
145
219
----
146
220
147
221
If you have a domain class in a package or are generating from a https://hibernate.org[Hibernate mapped class] remember to include the fully qualified package name:
148
222
149
-
[source,groovy]
223
+
[source,bash]
150
224
----
151
225
grails generate-all com.bookstore.Book
152
226
----
153
227
228
+
===== Generating Scaffolded Controllers and Services
229
+
230
+
To generate a scaffolded controller (using `@Scaffold` annotation):
231
+
232
+
[source,bash]
233
+
----
234
+
grails create-scaffold-controller Book
235
+
----
236
+
237
+
To generate a scaffolded service:
238
+
239
+
[source,bash]
240
+
----
241
+
grails create-scaffold-service Book
242
+
----
243
+
244
+
To generate both a scaffolded service and controller together:
245
+
246
+
[source,bash]
247
+
----
248
+
grails generate-scaffold-all Book
249
+
----
250
+
251
+
===== Command Options
252
+
253
+
The `create-scaffold-controller` command supports the following options:
254
+
255
+
* `--force` - Overwrite existing files
256
+
* `--namespace` - Set the controller namespace
257
+
* `--service` - Use `grails.plugin.scaffolding.RestfulServiceController` instead of `grails.rest.RestfulController`
258
+
* `--extends` - Specify a custom class to extend (default: `grails.rest.RestfulController`)
259
+
260
+
The `create-scaffold-service` command supports:
261
+
262
+
* `--force` - Overwrite existing files
263
+
* `--extends` - Specify a custom class to extend (default: `grails.plugin.scaffolding.GormService`)
264
+
265
+
The `generate-scaffold-all` command supports:
266
+
267
+
* `--force` - Overwrite existing files
268
+
* `--namespace` - Set the controller namespace
269
+
* `--serviceExtends` - Specify a custom class to extend for the service (default: `grails.plugin.scaffolding.GormService`)
270
+
* `--controllerExtends` - Specify a custom class to extend for the controller (default: `grails.plugin.scaffolding.RestfulServiceController`)
271
+
272
+
Examples:
273
+
274
+
[source,bash]
275
+
----
276
+
# Generate a scaffolded controller that uses a service
277
+
grails create-scaffold-controller Book --service
278
+
279
+
# Generate with a custom class to extend
280
+
grails create-scaffold-service Book --extends=com.example.MyCustomService
0 commit comments