扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:山风小子 来源:蛟龍居 2007年11月18日
关键字:
在本页阅读全文(共4页)
通过“grails create-app”这个命令,Grails自动帮我们创建了开发所需的工程环境。其实您现在就已经拥有了一个可运行的Web应用程序,然后进入demo目录(“cd demo”),输入“grails run-app”,回车,启动这个‘五脏俱全’的程序雏形,打开浏览器,输入 http://localhost:8080/demo ,回车,看到了吧 :) 让我们继续吧,请停止这个程序(Ctrl + C)
1,进入demo目录,在“命令行”中输入“cd demo”,回车,然后再输入“grails create-domain-class User”创建domain class即类似于pojo的pogo,它对应MVC中的Model,不过由Grails自动创建的pogo是空的,需要自己添加属性,约束(constraints)等。输出结果如下所示:
D:\Temp\grails_apps\demo>grails create-domain-class User Welcome to Grails 0.4.2 - http://grails.org/ Licensed under Apache Standard License 2.0 Grails home is set to: D:\D\MY_DEV\grails Base Directory: D:\Temp\grails_apps\demo Environment set to production Running script D:\D\MY_DEV\grails\scripts\CreateDomainClass.groovy [copy] Copying 1 file to D:\Temp\grails_apps\demo\grails-app\domain Created at D:\Temp\grails_apps\demo/grails-app/domain/User.groovy [copy] Copying 1 file to D:\Temp\grails_apps\demo\grails-tests Created Tests at D:\Temp\grails_apps\demo/grails-tests/UserTests.groovy D:\Temp\grails_apps\demo> |
2,进入D:\Temp\grails_apps\demo\grails-app\domain(这个目录中存放着所有的domain class),打开User.groovy,修改为如下内容:
class User { String name String password String toString() { " $name : $password " } static constraints = { name(blank: false ) password(blank: false , size: 6 .. 16 ) } |
D:\Temp\grails_apps\demo>grails generate-all User Welcome to Grails 0.4.2 - http://grails.org/ Licensed under Apache Standard License 2.0 Grails home is set to: D:\D\MY_DEV\grails Base Directory: D:\Temp\grails_apps\demo Environment set to production Running script D:\D\MY_DEV\grails\scripts\GenerateAll.groovy Compiling sources [delete] Deleting directory D:\Temp\grails_apps\demo\web-app\WEB-INF\grails-a pp [mkdir] Created dir: D:\Temp\grails_apps\demo\web-app\WEB-INF\grails-app\vie ws [mkdir] Created dir: D:\Temp\grails_apps\demo\web-app\WEB-INF\grails-app\i18 n [copy] Copying 2 files to D:\Temp\grails_apps\demo\web-app\WEB-INF\grails-a pp\views [copy] Copied 2 empty directories to 1 empty directory under D:\Temp\grails _apps\demo\web-app\WEB-INF\grails-app\views [native2ascii] Converting 1 file from D:\Temp\grails_apps\demo\grails-app\i18n t o D:\Temp\grails_apps\demo\web-app\WEB-INF\grails-app\i18n Attempting to load [13] core plugins Grails plug-in [i18n] with version [0.4.2] loaded successfully Grails plug-in [quartz] with version [0.4.2] loaded successfully Grails plug-in [core] with version [0.4.2] loaded successfully Grails plug-in [domainClass] with version [0.4.2] loaded successfully Grails plug-in [controllers] with version [0.4.2] loaded successfully Attempting to load [0] user defined plugins Grails plug-in [dataSource] with version [0.4.2] loaded successfully Grails plug-in [codecs] with version [0.4.2] loaded successfully Grails plug-in [hibernate] with version [0.4.2] loaded successfully Grails plug-in [services] with version [0.4.2] loaded successfully Grails plug-in [scaffolding] with version [0.4.2] loaded successfully Generating views for domain class [User] Generating list view for domain class [User] list view generated at D:\Temp\grails_apps\demo\.\grails-app\views\user\list.gsp Generating show view for domain class [User] Show view generated at D:\Temp\grails_apps\demo\.\grails-app\views\user\show.gsp Generating edit view for domain class [User] Edit view generated at D:\Temp\grails_apps\demo\.\grails-app\views\user\edit.gsp Generating create view for domain class [User] Create view generated at D:\Temp\grails_apps\demo\.\grails-app\views\user\create .gsp Generating controller for domain class [User] Controller generated at .\grails-app\controllers\UserController.groovy D:\Temp\grails_apps\demo> |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者