grails - grails为mysql View 创建域类

标签 grails

我有结合多个表列的mysql View 。我只想从此 View 中选择数据以在html页面中显示Web。无需使用GORM创建/更新/删除。如何为该 View 定义域类?

我的看法是这样的。

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

谢谢

最佳答案

假设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 - grails为mysql View 创建域类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14150467/

相关文章:

java - 无法使用提供的 Gradle 包装器或系统 Gradle 构建新创建的 Grails 6.0.0 应用程序

json - 如何为一个类设置多个自定义 JSON 编码器

grails - 如何修复未刷新的GrailsWebApplicationContext?

grails - Grails-如果存在其他标题,则无 session

postgresql - Class.forName ("org.postgresql.Driver") 同时使用 Postgresql

angularjs - 在grails 2.3.4中加载angularjs

grails - 用于在grails中检索状态更新项的相似/不同状态的条件或动态查找器

hibernate - 如何更新grails中的重复记录

postgresql - cloudfoundry 上的 grails 应用程序,如果定义了多数据源

sqlite - SQLite数据库中Grails域类中无法解析的日期