api - 如何限制grails中域属性的可见性?

标签 api grails dns

有没有建议的方法来限制域的可见性?

通常,您会做一些事情以获取一些供外部使用的界面:

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

但是默认情况下,不应填充域中的属性。所以我有话要说
SELECT id, name, foo1, foo2 FROM product

因此答案中仅包含属性列表。

最佳答案

您可以使用类似于 View 的第二个域类。诀窍是配置映射,使其具有与Product类相同的表:

class ProductView {

   String name
   Foo foo1
   Foo foo2

   static mapping = {
      table 'product'
   }
}

然后在您的UI中使用它:
def productList = ProductView.list()
withFormat {
  html {[productList:productList]}
  json { render productList as JSON }
  xml { render productList as XML }
  rss { render(feedType:"rss", productList)}
}

关于api - 如何限制grails中域属性的可见性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2789176/

相关文章:

grails - 加密 Grails Config 和 DataSource 文件中的一些文本

python - 身份验证 OneDrive API Python

ios - json 解析不正确

unit-testing - 使用 IVY 解析器进行 Grails 2.3 单元测试

sql - 如何使用executeUpdate()删除具有GORM(Grails)和HQL(Hibernate)的实体

validation - 在Grails中,如何在电子邮件验证程序约束中允许使用更新的DNS?

dns - 为什么会出现 No name servers found at child 错误?

windows - GetModuleFileName 不返回调用程序的路径

api - 有没有办法列出 TDB 存储中包含的模型?

Python 'requests' 库 - 定义特定的 DNS?