grails - grails正在重新格式化我的约会

标签 grails jodatime

我有一个groovy grails项目的以下域

class Title {

    // Automatic timestamping
    DateTime dateCreated
    DateTime lastUpdated

    String name
    LocalDate startDate
    LocalDate endDate

    static constraints = {
        name blank: false, maxSize: 100
        startDate nullable: true
        endDate nullable: true
        // TODO: Validation check to make sure endDate is after startDate
    }
}

开始日期使用jodatime的LocalDate

我的问题是,当我去更新startDate字段时,我必须使用以下格式mm/dd/yyyy,但是它将日期存储在数据库中作为yyyy-mm-dd。我想在输入字段中输入yyyy-mm-dd作为开始日期,因为那是它在数据库中的存储方式。如果尝试使用除斜杠以外的任何其他格式提交表单,则会出现以下错误

Failed to convert property value of type java.lang.String to required type org.joda.time.LocalDate for property startDate; nested exception is java.lang.IllegalArgumentException: Invalid format: "2014-01-01" is malformed at "14-01-01"



有谁知道如何解决这个问题?我应该重新格式化字符串吗?

最佳答案

您正在使用 Joda Time 插件吗?如果是,则应将字段映射到

static mapping = {
    startDate type: PersistentLocalDate
    endDate type: PersistentLocalDate
}

在您的模型中。

关于grails - grails正在重新格式化我的约会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20669061/

相关文章:

Grails (GORM) 多对一级联删除行为

java - 指定小时为 :minute, 但晚于现在的 Joda DateTime

java - 如何在 Joda 中将持续时间转换为周期?

json - Clojure 使用 ring-json 编码 Joda DateTime

java - joda时间消耗太多内存

grails - 如何测试注入(inject)到 Grails 中其他服务的服务?

jquery - 从下拉菜单更新选项

tomcat - grails run-war 的错误

list - Groovy/Grails - 需要检索列表索引值

java - 在 Java/scala 中将日期时间转换为纪元时间损失一小时