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