我从gsp视图中获取了一个包含日期和时间的字符串:
def name = params.name
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 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
答案 0 :(得分:1)
将String
转换为Date
,然后再将其传递给findByNameAndDateCreatedGreaterThan
,例如
def dataSearch = date + " " + time
Date date = Date.parse('yyyy-MM-dd HH:mm:ss', dataSearch)
MyDomain result = MyDomain.findByNameAndDateCreatedGreaterThan(name, date)