NutzCN Logo
问答 nutzwk时间查询异常,这是为什么?
发布于 3043天前 作者 qq_d6c9c504 1890 次浏览 复制 上一个帖子 下一个帖子
标签:

代码逻辑
if (!Strings.isBlank(subscribeAtStart)) {
cnd.and("subscribeAt", ">=", Castors.me().castTo(subscribeAtStart, Date.class));
}
if (!Strings.isBlank(subscribeAtEnd)) {
cnd.and("subscribeAt", "<=", new DateTime(Castors.me().castTo(subscribeAtStart, Date.class)).withTime(23,59,59,59).toDate());
}
return wxUserService.data(length, start, draw, order, columns, cnd, null);

异常信息
2016-08-23 15:13:26,913 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:339) DEBUG - SELECT COUNT(*) FROM wx_user  WHERE wxid=? AND subscribeAt >= ? AND subscribeAt <= ?
    |                                1 |                   2 |                   3 |
    |----------------------------------|---------------------|---------------------|
    | 5d66443f8bd94f3db9e84b6aa5798ac2 | 2016-08-16 00:00:00 | 2016-08-16 23:59:59 |
  For example:> "SELECT COUNT(*) FROM wx_user  WHERE wxid='5d66443f8bd94f3db9e84b6aa5798ac2' AND subscribeAt >= '2016-08-16 00:00:00' AND subscribeAt <= '2016-08-16 23:59:59'"
2016-08-23 15:13:26,917 cn.wizzer.common.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) DEBUG - [POST]URI=/nutzwk/private/wx/user/data/5d66443f8bd94f3db9e84b6aa5798ac2 101ms
2016-08-23 15:13:26,918 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) WARN  - Error@/private/wx/user/data/5d66443f8bd94f3db9e84b6aa5798ac2 :
org.nutz.dao.DaoException: org.nutz.castor.FailToCastObjectException: Fail to cast 'Tue Aug 16 00:00:00 CST 2016' to <int>
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:128)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:81)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:70)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:267)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:275)
	at org.nutz.dao.impl.NutDao._count(NutDao.java:704)
	at org.nutz.dao.impl.NutDao.count(NutDao.java:666)
	at cn.wizzer.common.base.Service.data(Service.java:411)
	at cn.wizzer.modules.back.wx.controllers.WxUserController.data(WxUserController.java:86)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)

这个位置贴代码或日志,不要移除前后标识符

```

3 回复

数据库里面可是数值.

cnd.and("subscribeAt", "<=", new DateTime(Castors.me().castTo(subscribeAtStart, Date.class)).withTime(23,59,59,59).toDate().getTime()); // getTime嘛

ok了,感谢兽总的回答

        int startT = DateUtil.getTime(Strings.sBlank(beginDate) + " 00:00:00");
        int endT = DateUtil.getTime(Strings.sBlank(endDate) + " 23:59:59");
添加回复
请先登陆
回到顶部