代码之家  ›  专栏  ›  技术社区  ›  Steve Wall

Grails默认日期

  •  1
  • Steve Wall  · 技术社区  · 16 年前


    谢谢,

    2 回复  |  直到 16 年前
        1
  •  2
  •   uthark    16 年前

    你能做到的 grails install-templates 自定义模板,用于渲染。

    $PROJECT/src/templates/scaffolding/renderEditor.template renderDateEditor 应该根据您的需要定制。

        2
  •  0
  •   ataylor    16 年前

    无论域对象中的默认值是什么,都将在创建时显示在窗体中。

    class Test {
        Date aDate
    }
    

    在该示例中,域对象具有不可为空的日期,因此默认值是新构造的日期。如果域对象更改为:

    class Test {
        Date aDate
        static constraints = {
            aDate(nullable:true)
        }
    }
    

    如果要明确设置默认值,只需使用域对象初始值设定项对其进行赋值:

    class Test {
        Date aDate = Date.parse("yyyy-MM-dd", "2010-01-01")
        static constraints = {
            aDate(nullable:true)
        }
    }