NumberFormatException For input string when try to do a date search in grails

对着背影说爱祢 提交于 2019-12-12 04:29:24

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!