grails - 在 grails 的基类中添加新属性后出错

标签 grails inheritance

我创建了一个非常简单的 Grails 项目(IntelliJ IDEA 14.0.2),名为 CheckInheritance
两个域类:

package checkinheritance

class Parent {

  String name

  static constraints = {
  }
}


package checkinheritance

class Child extends Parent{

  String prename

  static constraints = {
  }
}

我为子类生成了 Controller 类和 View
当我启动应用程序时,一切正常。

然后我将属性“描述”添加到父类:
package checkinheritance

class Parent {

  String name
  String description

  static constraints = {
  }
}

我删除了 Child 类的 View 和 Controller 。然后我为子类重新生成文件( View 、 Controller )。
当我启动应用程序时,我想添加一个 Child 对象。
输入数据(在所有输入字段中)并按“Anlegen”(保存)后,我收到一个错误,即属性“description”不能为空(请参阅带有德语消息的屏幕截图)。
当基类是抽象的时也会发生这种情况。
数据库是空的并且是新的(开发模式)。

这是我为属性“描述”生成的 _form.gsp:
<div class="fieldcontain ${hasErrors(bean: childInstance, field: 'description', 'error')} required">
    <label for="description">
        <g:message code="child.description.label" default="Description" />
        <span class="required-indicator">*</span>
    </label>
    <g:textField name="description" required="" value="${childInstance?.description}"/>

</div>

我是否必须为基类中的新属性“描述”添加一些内容?

这是我的环境:

申请状态
应用版本:0.1
Grails 版本:2.4.4
Groovy 版本:2.3.7
JVM版本:1.8.0_25
重新加载事件:true
Controller :3
域:2
服务:3
标签库:15
已安装的插件
restResponder - 2.4.4
日志记录 - 2.4.4
i18n - 2.4.4
数据绑定(bind) - 2.4.4
核心 - 2.4.4
小服务程序 - 2.4.4
编解码器 - 2.4.4
webxml - 1.4.1
数据库迁移 - 1.4.0
jQuery - 1.11.1
数据源 - 2.4.4
urlMappings - 2.4.4
Controller - 2.4.4
Assets 管道 - 1.9.9
过滤器 - 2.4.4
域类 - 2.4.4
Controller 异步 - 2.4.4
mime 类型 - 2.4.4
休眠4 - 4.3.6.1
转换器 - 2.4.4
groovyPages - 2.4.4
服务 - 2.4.4
验证 - 2.4.4
脚手架 - 2.1.2
缓存 - 1.1.8

最佳答案

默认情况下是强制性的描述。
因为它是可空的 = false;

你可以试试

    String name
    String description

    static constraints = {
    description nullable: true

    }

关于grails - 在 grails 的基类中添加新属性后出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27963917/

相关文章:

java - 为什么在覆盖时不允许缩小方法的范围

grails - 不同架构中的表之间的关系映射

grails - 更改不会自动重新加载到 Controller 中

Grails 使用 gstring 访问嵌套字段

swift - 将 UIGestureRecorgniser 的委托(delegate)设置为父级

java - 如何在 Android 中的 Activity 之间访问相同的变量

grails - 如何在 Grails 3.3.0 中集成 paypal 支付网关

grails - Chrome开发人员工具显示Grails应用程序中动态生成的文件的下载状态已取消

c++ - 在此范围内未声明构造函数 'cout'

java - SINGLE_TABLE @Inheritance 不继承的 EclipseLink JPA 问题