简体   繁体   English

grails为mysql视图创建域类

[英]grails create domain class for mysql view

I have mysql view with combining multiple tables column. 我有结合多个表列的mysql视图。 I want to only select data from this view to display web in html page. 我只想从此视图中选择数据以在html页面中显示网络。 no need to create/update/delete using GORM. 无需使用GORM创建/更新/删除。 how can I define the domain class for this view? 如何为该视图定义域类?

my view is like this. 我的看法是这样的。

view name: testview
col1 int,
col2 varchat(50),
col3 date

thanks 谢谢

Assuming col1 is the primary key: 假设col1是主键:

class View {
    Integer col1
    String col2
    Date col3

    static mapping = {
        table name: "testview"
        version false
        id name: "col1", generator: "assigned"

        // These are unnecessary unless you change the name of the fields
        col1 column: "col1"
        col2 column: "col2"
        col3 column: "col3"
    }
}

Grails gorm does not provide direct access to views, but you can try HQL, or refer to Elegant ways to handle database views on hibernate entities? Grails gorm不提供对视图的直接访问,但是您可以尝试使用HQL,还是可以参考优雅的方式来处理休眠实体上的数据库视图? .

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

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