- Grails 1.1 Web Application Development
- Jon Dickinson
- 197字
- 2021-04-01 14:19:30
Bootstrapping demo data
You saw earlier that Grails comes pre-configured with an in-memory HSQLDB database. The benefit of this is that you don't need to configure a database server to get started. The problem is that whenever you restart Grails, all your data is lost. Grails provides a handy notion of Bootstrapping data, so a set of demo data can be loaded into your application during startup. At the very least, you will want to add the User
and Administrator
roles to this bootstrap to save you re-creating them each time.
The BootStrap
class can be found under the grails-app/conf
folder. Update the init
code block to create and save the two new roles:
import app.Role class BootStrap { def init = { servletContext -> def user = new Role(name: 'User').save() def admin = new Role(name: 'Administrator').save() } def destroy = { } }
The BootStrap
class is able to interact with the ServletContext
of the application as it is passed as an argument to the init
closure.
Now that the roles have been pre-configured for the application, it is possible to create users that belong to one of these roles as shown in the following screenshot:

- 中文版SolidWorks 2015技術大全
- Excel 2010 商務數(shù)據(jù)分析與處理(第2版)
- 中文版 Photoshop CC 從入門到精通
- 老郵差·Photoshop數(shù)碼照片處理技法:人像篇(修訂版)
- 中文版Dreamweaver基礎培訓教程
- Microsoft Azure: Enterprise Application Development
- Unity 3D游戲開發(fā)(第2版)
- Altium Designer 20 中文版從入門到精通
- Adobe創(chuàng)意大學Premiere Pro影視剪輯師標準實訓教材(CS6修訂版)
- Photoshop人像精修秘笈
- Moodle 2.0 for Business Beginner's Guide
- 中文版Photoshop 2020基礎培訓教程
- NumPy 1.5 Beginner's Guide
- 攝影師的后期課:RAW格式技法篇
- Panda3d 1.7 Game Developer's Cookbook