内容简介
上一章花了很多时间建立领域模型,这一章就要看怎么用了。
1、先给所有的模型创建控制器
grails create-controller com.grailsinaction.User
grails create-controller com.grailsinaction.Profile
grails create-controller com.grailsinaction.Post
grails create-controller com.grailsinaction.Tag
2、修改所有的Controller,装入自动脚手架
1 package com.grailsinaction
2
3 class TagController {
4
5 def scaffold = true
6 }
3、运行系统,就能看到自动脚手架的威力了,慢慢体会
grails run-app
http://localhost:8080/hubbu
4、回头看看建立模型时的一些验证,在页面上操作时应该都是有效的,如:
User
1 static constraints = {
2 password(size: 6..8, validator: { passwd, user ->
3 passwd != user.userId
4 })
5 dateCreated()
6 profile(nullable: true)
7 }
Profile
1 static constraints = {
2 fullName(nullable: true)
3 bio(nullable: true, maxSize: 1000)
4 homepage(url: true, nullable: true)
5 email(email: true, nullable: true)
6 photo(nullable: true)
7 country(nullable: true)
8 timezone(nullable: true)
9 jabberAddress(email: true, nullable: true)
10 }
不过,错误提示有点难懂,不像是给最终用户看的。所以提示的内容需要客户化
5、客户化错误提示
打开/grails-app/i18n/messages.properties就能看到所有系统中已有的错误提示,修改一下就行了,如果使用的是中文环境,就直接修改messages_zh_CN.properties文件即可,这里主要的内容是参数传递需要理解
{0} 属性
{1} 类
{2} 值
{3} 从
{4} 到
6、我们在使用自动生成的页面可以看到,组合框选择关联关系对象时,是使用的对象ID,这个选择很不友好,我们可以用toString()方法修改对象的默认显示内容
,如Profile
1 String toString() {
2 "Profile for ${fullName} (${id})"
3 }
使用下拉选择时的内容就是一个字符串了。
7、我们发现只要建立好脚手架,所有功能都已经完成了,只是有些地方不是很友好而已。这里有个问题,我们真的要使用脚手架产生的应用吗?当我们的业务逻辑变的很复杂,模型很庞大的时候,就不那么好组织这些功能了,所以,官方文档的建议还是自定义UI。下面我们就开始调整页面
分享到:
相关推荐
groovy-grails-tool-suite-3.6.4.RELEASE-e4.4.2-win32-x86_64.part1 共两个压缩包,解压后将扩展名.zip.bak改为.zip再次解压。
elasticsearch-grails-plugin, 恢复的ElasticSearch grails插件 Elasticsearch插件插件这个项目是一个基于Elasticsearch的插件,这个项目是基于的人完成的伟大工作的。你为什么想要为原来的Elasticsearch插件提供...
groovy-grails-tool-suite-3.6.4.RELEASE-e4.4.2-win32-x86_64.part2 共两个包,解压后需要将扩展名.zip.bak改名为.zip重新解压。 http://dist.springsource.com/release/STS/3.8.1.RELEASE/dist/ e4.6/spring-tool-...
Grails In Action.pdf ebook
Grails in Action pdf
Getting-Started-with-Grails-Chinese,一本不错的grails入门书籍,希望对有志于grails的朋友们有用。
Grails in Action - Presentation pdf
Grails in Action Grails in Action Grails in Action Grails in Action Groovy in Action Grails in Action Grails in Action Groovy in Action Groovy in Action
Grails In Action 2009最新版,英文的。很详细,学习groovy和grails的不二之选。
ant-1.9.4jarant-antlr-1.9.4.jarant-junit-1.9.4jar ant-launcher-1.9.4.jar bsf-2.4.0.jar commons-cli-1.2jar commons-logging-1.2.jar gpars-1.2.1.jar groovy-2.4.5jar groovy-ant-2.4.5.jar ...
Grails入门指南中文pdf -- 针对grails1.0.4更新,附加idea8 开发grails的流程
基于java的动态语言Groovy 构建的敏捷web开发框架grails经典入门教程
wsdl2java源码 请注意,当前的 3.x 版本使用 cxf 3.0.4 并且需要 WSS4J ...grails-app\endpoints** 和 grails-app\services** 目录中自动装配配置的类 端点创建脚本 create-endpoint 和 create-endpoin
实测可用
实测可用
实测可用
实测可用