【问题标题】:Grails command/domain object propertyNameGrails 命令/域对象 propertyName
【发布时间】:2013-10-17 18:00:52
【问题描述】:

当域/commandObjects 中的任何验证失败时,错误消息将取自 message.properties 并使用 fieldName 进行格式化,即

Property {0} must be a valid number

将显示为

Property deviceTemperature must be a valid number

如何在不更改错误消息的情况下将字段名称更改为可读字符串,例如:

Property Device temperature must be a valid number

【问题讨论】:

    标签: grails gsp


    【解决方案1】:

    如果您查看生成的 GSP 表单,您会发现 Grails 约定。示例:

    class Book {
      String title
    }
    
    <label for="title">
      <g:message code="book.title.label" default="Title" />
    </label>
    

    所以你可以随时使用domainClassName.propertyName.label

    【讨论】:

      猜你喜欢
      • 2014-06-07
      • 2017-08-24
      • 1970-01-01
      • 2010-12-24
      • 2015-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-06
      相关资源
      最近更新 更多