简体   繁体   English

如何在Grails中创建“视图”域对象

[英]How to create a “view” domain object in Grails

I'm trying to adapt a legacy database to a grails application and I'm not sure how can I do it on grails. 我正在尝试将遗留数据库调整为grails应用程序,我不知道如何在grails上执行此操作。 I have a huge table (with columns colA, colB, ..., colZ) that I only want to map some of them as fields (say colA, colC, colE) like a database view, this domain class is intended to be read-only so it would not be a problem to not have the save, update and delete operations. 我有一个巨大的表(列colA,colB,...,colZ),我只想将它们中的一些映射为字段(比如colA,colC,colE),就像数据库视图一样,这个域类旨在被读取 - 因此没有保存,更新和删除操作不会有问题。

How should I create my domain class? 我应该如何创建我的域类?

EDIT 编辑

I need to adapt a query to a domain object, this query has a lot of group by expressions (max, min, count, etc.) and I would like to adapt this query so that everytime I call DomainObj.list() Grails would run this query and load all the data from the database within the GORM proxy. 我需要调整一个域对象的查询,这个查询有很多group by表达式(max,min,count等),我想调整这个查询,这样每次调用DomainObj.list()Grails就会运行此查询并从GORM代理中加载数据库中的所有数据。

If it is read only, just create a domain object containing the fields you are interested in. That should be no problem. 如果它是只读的,只需创建一个包含您感兴趣的字段的域对象。这应该没问题。

Remember however that GORM will create a "version" column as default, but this can be disabled: 但请记住,GORM会默认创建“版本”列,但可以禁用此列:

static mapping = {
      table 'people'
      version false
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM