如何限制的Grails域属性的知名度? [英] How to restrict visibility of domain properties in grails?

查看:217
本文介绍了如何限制的Grails域属性的知名度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有限制域名的Grails的知名度任何推荐的方式?

Is there any recommended way to restrict the visibility of a domain in grails?

通常你你喜欢的东西拿到外用一些接口:

Normally you you do something like to get some interface for external use:

def productList = Product.list()
withFormat {
  html {[productList:productList]}
  json { render productList as JSON }
  xml { render productList as XML }
  rss { render(feedType:"rss", productList)}
}

其等于

SELECT * FROM product

但默认情况下有没有不应该被填充的一个域proerties。所以,我需要的东西说。

But by default there proerties in a domain that should not be populated. So I need something to say

SELECT id, name, foo1, foo2 FROM product

所以只有一个的属性列表被包含在应答

so only a list of properties is included in the answer.

推荐答案

您可以使用第二个域类有点像视图。关键是要配置映射,它具有相同的表作为产品类:

You can use a second domain class sort of like a view. The trick is to configure the mapping so it has the same table as the Product class:

class ProductView {

   String name
   Foo foo1
   Foo foo2

   static mapping = {
      table 'product'
   }
}

然后使用你的用户界面:

Then use that in your UI:

def productList = ProductView.list()
withFormat {
  html {[productList:productList]}
  json { render productList as JSON }
  xml { render productList as XML }
  rss { render(feedType:"rss", productList)}
}

这篇关于如何限制的Grails域属性的知名度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆