gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 15:30:19 24 4
gpt4 key购买 nike

我有一个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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com