Grails-日期0000:00:00 00:00:00

时间:2019-04-03 18:44:29

标签: mysql grails

我需要能够以一种不好的方式放置我的变量“ lastupdate” 0000:00:00 00:00:00,但是我不知道该怎么做,因为成为日期会给我一个错误< / p>

class Dialernumbers {
    Integer campaign
    Date lastupdate

    static mapping = {
                    id column: "id", type:"long", sqlType: "int", generator: 'increment'
                        version false
                    }

       static constraints = {
                    lastupdate nulleable: true
                    }

}

1 个答案:

答案 0 :(得分:0)

Issabel - Asterisk sounds like a co worker :) anyhow what I suggest is you don't do any of above instead do this create another map inside the class

class Dialernumbers {
    Integer campaign
    Date lastupdate

    static mapping = {
                    id column: "id", type:"long", sqlType: "int", generator: 'increment'
                        version false
                    }


       Map loadValues() { 
           Map m =[:]
           m.campaign=this.campaign
           m.lastUpdate=this.lastUpdate ? this.lastUpdate : '00/00/00'

           return m
       }
       static constraints = {
          lastupdate nullable: true
       }

}

Now when you want to call class for Issabel - Asterisk you call

Dialernumbers dl = Dialernumbers.get(1L)
Issabel.dateValue = dl.loadValues().lastUpdate 

//Map values  = dl.loadValues()
//Issabel.dateValue = values.lastUpdate  

This way you keep something that is a date field as a date field so it is then available for Hibernate and db queries just like a date and is also nullable in which case is returned in a specific format for your current requirements using loadValues and could be altered to another method for something else nullable NOT nulleable