How to restrict visibility of domain properties in grails?

后端 未结 1 813
温柔的废话
温柔的废话 2021-02-11 05:09

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:



        
1条回答
  •  梦如初夏
    2021-02-11 05:53

    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)}
    }
    

    0 讨论(0)
提交回复
热议问题