【问题标题】:One to one Relationship display in GrailsGrails 中的一对一关系显示
【发布时间】:2019-09-30 05:03:24
【问题描述】:

我无法在 grails 中显示一对一关系。我在 grails > 命令行中使用了 grails create-domain-class 和 grails create-all 并且正在使用 h2 数据库。

class Employee {

int id
String firstName
String lastName
Country country
Classification classification




static constraints = {
  }
} 


package com.app

class Country {

int id
String countryName
static belongsTo = [employee: Employee]



static constraints = {
  }
}



package com.app

class Classification {

int id
String classificationText

static belongsTo = [employee:Employee]

static constraints = {
   }
}

我的域类如上所述,在 com.app.Employee 上使用 create-all 后,它会生成剩余点,然后我使用 run-app 启动服务。在 localhost:8080 中显示时,我无法编辑 Country 和 Classification 类变量以使用 countryName 和分类文本。它只显示这些空滚动框。有人知道解决办法吗?

【问题讨论】:

    标签: grails groovy


    【解决方案1】:

    您必须先创建分类和国家/地区。然后,当您在 Country 和 Classification 字段中创建 Employee 时,您必须输入 Country 和 Classification id。

    所以,你创建一个 Country,它被存储并有一个 id,然后你创建一个 Cassification,它被存储并有另一个 id,最后你创建 Employee 并使用创建的 id 将它与 Country 和分类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-19
      • 1970-01-01
      • 2018-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多