[英]Is there a default max to gorm list method on domain object in grails 3.2
[英]Grails GORM domain object naming conventions for date fields, and persistence consequences
這個問題與Grails 2.1.1有關。 我有一個域對象,其中包含在控制器中設置的3個日期字段。 我有一個錯誤,其中控制器中設置的日期被忽略,並替換為當前日期
奇怪的是,僅當我將域對象中的相應字段重命名為具有“ date”后綴時,此行為才得以解決。
我想知道:
下面提供了分析和代碼示例:
原始域對象和控制器-在這種情況下,為“ dateCreated”和“ lastUpdated”設置的值將被系統日期忽略並覆蓋。
class User {
String name
String title
String firstName
String lastName
Date companyCreationDate
Date dateCreated //works when renamed to createdDate (and controller updated accordingly)
Date lastUpdated //works when renamed to lastUpdatedDate (and controller updated accordingly)
static mapping = {
id column:'record_id'
}
static constraints = {
id()
title(blank: false, maxSize: 35)
firstName(blank: false, minSize: 1, maxSize: 35)
lastName(blank: false, minSize: 1, maxSize: 35)
}
}
類UserController {
static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
static df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH)
def save() {
def user = new User()
user.name = params.name
user.companyCreationDate = df.parse("2006-09-07 13:26:15");
user.title = params._title
user.firstName = params._fname
user.lastName = params._lName
user.creationDate = df.parse("2006-09-07 00:00:00");
user.lastUpdatedDate = df.parse("2006-09-07 00:00:00");
if (user.validate()){
user.clearErrors();
if (user.save(flush: true)) {
flash.message = message(code: 'default.created.message', args: [message(code: 'registration.label', default: 'Registration'), user.id])
redirect(action: "show", id: user.id)
}
}
else
{
render(view: "create", model: [userInstance: user])
}
在Hibernate中設置跟蹤選項之后,我注意到在保存域對象(即調用“ save(flush:true)”)和Hibernate執行持久性操作之間發生了這種轉換。
您可以通過將autoTimestamp設置為false來禁用此功能: Grails Doc
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.