- 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:

- 中文版SketchUp 2022完全實(shí)戰(zhàn)技術(shù)手冊(cè)
- Vue.js框架與Web前端開(kāi)發(fā)從入門到精通
- 邊做邊學(xué):Photoshop CS6 圖像制作案例教程
- Photoshop CC 實(shí)戰(zhàn)入門
- CoffeeScript Application Development
- Photoshop+Adobe Camera Raw+Lightroom(攝影后期照片潤(rùn)飾實(shí)戰(zhàn))
- Photoshop CC從入門到精通(全彩超值版)
- Photoshop CC 2017從入門到精通
- 輕松玩轉(zhuǎn)3D One AI
- Autodesk Ecotect Analysis綠色建筑分析應(yīng)用
- SolidWorks 2020中文版從入門到精通
- PPT設(shè)計(jì)與制作實(shí)戰(zhàn)教程
- 從零開(kāi)始:Indesign CC 2019設(shè)計(jì)基礎(chǔ)+商業(yè)設(shè)計(jì)實(shí)戰(zhàn)
- 邊做邊學(xué):CorelDRAW X6圖形設(shè)計(jì)案例教程(第2版)(微課版)
- WordPress MU 2.8: Beginner's Guide