berFormatException在尝试在grails中执行日

berFormatException在尝试在grails中执行日

本文介绍了NumberFormatException在尝试在grails中执行日期搜索时对于输入字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  def name = params.name $ b $从gsp视图中获得一个字符串b def time = params.minutes 
def date = params.datapicker

现在,我想要按日期和名称在我的域名中进行搜索。因此,我加入了日期和时间并进行搜索:

$ $ $ $ $ $ $ $ def dataSearch = date ++ time
MyDomain result = MyDomain.findByNameAndDateCreatedGreaterThan(name,dataSearch)

但是,我收到此错误:

  2016-05-26 09:56:44,488 [http-bio-8090-exec-3] ERROR errors.GrailsExceptionResolver  -  NumberFormatException发生在处理请求时:[POST] / myClass / search-参数:

名称:Bob
分钟:18:17:42
按钮:搜索
datapicker: 2016-04-28
输入字符串:2016-04-28 18:17:42。 Stacktrace如下:
消息:输入字符串:2016-04-28 18:17:42
行|方法
- >> 65 | for java.lang.NumberFormatException中的forInputString转换您的<$> $ <$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $在将它传递给 findByNameAndDateCreatedGreaterThan 之前,将c $ c> String
改为a Date p>

  def dataSearch = date ++ time 
Date date = Date.parse('yyyy-MM-dd HH: mm:ss',dataSearch)
MyDomain result = MyDomain.findByNameAndDateCreatedGreaterThan(name,date)


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
解决方案

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)

这篇关于NumberFormatException在尝试在grails中执行日期搜索时对于输入字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 21:51