问题
I get from the gsp view a string with the date and time:
def name = params.name
def time = params.minutes
def date = params.datapicker
Now, I want to do a search in my domain by date and name. So, I join the date and time and do the search:
def dataSearch = date + " " + time
MyDomain result= MyDomain.findByNameAndDateCreatedGreaterThan(name, dataSearch)
But, I'm getting this error:
2016-05-26 09:56:44,488 [http-bio-8090-exec-3] ERROR errors.GrailsExceptionResolver - NumberFormatException occurred when processing request: [POST] /myClass/search- parameters:
name: Bob
minutes: 18:17:42
button: search
datapicker: 2016-04-28
For input string: "2016-04-28 18:17:42". Stacktrace follows:
Message: For input string: "2016-04-28 18:17:42"
Line | Method
->> 65 | forInputString in java.lang.NumberFormatException
回答1:
Convert your String
to a Date
before passing it to findByNameAndDateCreatedGreaterThan
, e.g.
def dataSearch = date + " " + time
Date date = Date.parse('yyyy-MM-dd HH:mm:ss', dataSearch)
MyDomain result = MyDomain.findByNameAndDateCreatedGreaterThan(name, date)
来源:https://stackoverflow.com/questions/37456277/numberformatexception-for-input-string-when-try-to-do-a-date-search-in-grails