NutzCN Logo
问答 nutz 中sql的查询到的信息
发布于 2658天前 作者 qq_5d22b496 6366 次浏览 复制 上一个帖子 下一个帖子
标签:

大神,我想请问一下,就是我自定义了sql,然后我要查询到的信息是其中数据的和(sum),还有其他的一些时间的信息,然后我自定义类去接收查询到的数据可是全都是null,是不是必须和数据库中的字段相同的类去接收才行????如果要接收到他统计后的字段该怎么办呢??

Sql sql = Sqls.create(
				"select sum(changenum)as sc, changeReason, from_unixtime(UNIX_TIMESTAMP(time), '%y-%m-%d')as days from (select * from log_diamond where time > '2017-09-09')demo group by changeReason, days");

	    sql.setCallback(Sqls.callback.entities());
		sql.setEntity(dao.getEntity(T1_moneyCountBean.class));
		dao.execute(sql);
		 List<T1_moneyCountBean> list = sql.getList(T1_moneyCountBean.class);
12 回复
Sql sql = Sqls.create(
				"select sum(changenum)as sc, changeReason, from_unixtime(UNIX_TIMESTAMP(time), '%y-%m-%d')as days from (select * from log_diamond where time > '2017-09-09')demo group by changeReason, days");

		sql.setCallback(Sqls.callback.entities());
		sql.setEntity(dao.getEntity(T1_moneyCountBean.class));
		dao.execute(sql);
		List<T1_moneyCountBean> list = sql.getList(T1_moneyCountBean.class);

sum之类的映射不了的,用Record来接收吧

好的,谢谢兽总

大神,不对呀。给我报异常。不能那样转

`` com.backend.bean.T1_Diamond cannot be cast to org.nutz.dao.entity.Record

 com.backend.bean.T1_Diamond cannot be cast to org.nutz.dao.entity.Record
Sql sqlactive2 = Sqls.create("select sum(changenum)as sc, changeReason, from_unixtime(UNIX_TIMESTAMP(time), '%y-%m-%d')as days from (select * from log_diamond where time >= (@time1) and time < (@time2) and playerID in (@ids1))demo group by changeReason, days");
					sqlactive2.setParam("ids1", keepPlayers.toArray());
					sqlactive2.setParam("time1", TimeLogic.backStartTimeString(time));
					sqlactive2.setParam("time2", TimeLogic.backEndTimeString(time));
					
					sqlactive2.setCallback(Sqls.callback.entities());
					sqlactive2.setEntity(logDao.getEntity(T1_Diamond.class));
					logDao.execute(sqlactive2);
				    List<Record> list = sqlactive2.getList(Record.class);

找到原因了。因为一个类没变成Record!!!但是运行起来却报warn

WARN  - No @Table found, fallback to use table name='record' for type 'org.nutz.dao.entity.Record'

Sqls.queryRecord

哦哦。所以我这边不用设置回调了??直接运行??

添加回复
请先登陆
回到顶部