声明:JavaEye新闻文章的版权属于JavaEye网站所有,严禁任何网站转载本文,否则必将追究法律责任!
Grails 1.0-RC2 发布,看到新增不少功能,心中窃喜啊
现在简介一下主要变动:
那么在处理这个请求的时候,可以使用withFormat方法:
自动从XML/JSON中构建对象
基于XML/JSON的请求现在可以通过params自动的构造对象,如以下XML请求:
那在controller中可以这样使用:
支持自定义外键字段的映射和JoinTable
Grails的GORM DSL现在已经支持外键字段的映射和Join Table,比如要改变one-to-one的外键可以这样做:
你也可以单向的one-to-many或者many-to-many关联的join table和columns,比如:
现在简介一下主要变动:
- 移植到最新的spring2.5
- 新的参考文档 去官方文档,个人感觉挺舒服的,而且也很有条理
- 内容协商(ContentNegotiation)支持 Grails现在可以通过Accept/Content-Type HTTP headers, a parameter or URI 扩展来提供支持,其MIME类型可以在Config.groovy配置
grails.mime.types = [ html: ['text/html','application/xhtml+xml'],
xml: ['text/xml', 'application/xml']
// etc.
]
那么在处理这个请求的时候,可以使用withFormat方法:
def list = {
def results = Book.list()
withFormat {
html bookList:result
xml { render results as XML }
}
}
<book>
<title>The Stand</title>
<author>Stephen King</author>
...
</book>
那在controller中可以这样使用:
def save = {
def b = new Book(params['book'])
if(b.save()) {
// deal with book
}
}
class Book {
Author author
static mapping = {
columns {
author column:'auth_id'
}
}
}
你也可以单向的one-to-many或者many-to-many关联的join table和columns,比如:
class Author {
static hasMany = [books:Book]
static mapping = {
columns {
books joinTable:[name:'authors_books', key:'book_id', column:'author_id']
}
}
}


评论 共 3 条 发表评论
山风小子 2007-12-05 21:02
可以的
shiren1118 2007-12-05 18:24
又可以自由的框架
希望它越作越好
lgx522 2007-12-05 08:28
如果是那样的话,Grails是值得研究的,毕竟Java世界的类库资源已经浩如烟海了。