NutzCN Logo
问答 查询语句获取回调结果,设置实体类不能用Map么
发布于 2306天前 作者 qq_e79520c3 2062 次浏览 复制 上一个帖子 下一个帖子
标签:

------------------------dao--------------------------
@Override
public List getAreaPersonStructure(){
Sql sql = Sqls.create(
"select * from (SELECT (CASE WHEN POPULATION_MODEL.age<=14 THEN '0-14岁'" +
" WHEN POPULATION_MODEL.age>14 and POPULATION_MODEL.age<=64 THEN '14-64岁'" +
" WHEN POPULATION_MODEL.age>64 THEN '65岁及以上'" +
" END)ranges, TO_CHAR(COUNT(1)) count from POPULATION_MODEL where POPULATION_MODEL.age is not null GROUP BY (CASE WHEN POPULATION_MODEL.age<=14 THEN '0-14岁'" +
" WHEN POPULATION_MODEL.age>14 and POPULATION_MODEL.age<=64 THEN '14-64岁'" +
" WHEN POPULATION_MODEL.age>64 THEN '65岁及以上'" +
" END))");
Entity entity = dao().getEntity(Map.class);
sql.setEntity(entity);
sql.setCallback(Sqls.callback.entities());
dao().execute(sql);
return sql.getList(Map.class);
}
--------------------控制台--------------------------
[DEBUG] 2018-08-29 16:35:59,049 org.nutz.mongo.ZMoCo.drop(ZMoCo.java:294) - db.statistics_table_data.drop()
[DEBUG] 2018-08-29 16:35:59,054 com.mongodb.diagnostics.logging.SLF4JLogger.debug(SLF4JLogger.java:56) - Sending command {drop : BsonString{value='statistics_table_data'}} to database GeoData on connection [connectionId{localValue:2, serverValue:10}] to server 127.0.0.1:27017
[DEBUG] 2018-08-29 16:35:59,146 com.mongodb.diagnostics.logging.SLF4JLogger.debug(SLF4JLogger.java:56) - Command execution completed
org.nutz.dao.DaoException: Need non-arg constructor : interface java.util.Map
at org.nutz.dao.impl.entity.NutEntity.(NutEntity.java:190)
at org.nutz.dao.impl.entity.AnnotationEntityMaker._createNutEntity(AnnotationEntityMaker.java:623)
at org.nutz.dao.impl.entity.AnnotationEntityMaker.make(AnnotationEntityMaker.java:90)
at org.nutz.dao.impl.EntityHolder.getEntity(EntityHolder.java:72)
at org.nutz.dao.impl.NutDao.getEntity(NutDao.java:682)
at cn.wizzer.app.templet.modules.service.impl.PopulationServiceImpl.getAreaPersonStructure(PopulationServiceImpl.java:426)

```

4 回复
   public  List<Map>  getAreaPersonStructure(){
       Sql sql = Sqls.create(
        "select  * from (SELECT  (CASE WHEN POPULATION_MODEL.age<=14 THEN '0-14岁'" +
               "               WHEN POPULATION_MODEL.age>14 and POPULATION_MODEL.age<=64 THEN '14-64岁'" +
               "               WHEN POPULATION_MODEL.age>64 THEN '65岁及以上'" +
               "               END)ranges, TO_CHAR(COUNT(1)) count   from POPULATION_MODEL where POPULATION_MODEL.age  is  not  null  GROUP BY (CASE WHEN POPULATION_MODEL.age<=14 THEN '0-14岁'" +
               "               WHEN POPULATION_MODEL.age>14 and POPULATION_MODEL.age<=64 THEN '14-64岁'" +
               "               WHEN POPULATION_MODEL.age>64 THEN '65岁及以上'" +
               "               END))");
       Entity<Map> entity = dao().getEntity(Map.class);
       sql.setEntity(entity);
       sql.setCallback(Sqls.callback.entities());
       dao().execute(sql);
       return sql.getList(Map.class);
   }

-------------------------------
[DEBUG] 2018-08-29 16:35:59,146 com.mongodb.diagnostics.logging.SLF4JLogger.debug(SLF4JLogger.java:56) - Command execution completed
org.nutz.dao.DaoException: Need non-arg constructor : interface java.util.Map
	at org.nutz.dao.impl.entity.NutEntity.<init>(NutEntity.java:190)
	at org.nutz.dao.impl.entity.AnnotationEntityMaker._createNutEntity(AnnotationEntityMaker.java:623)
	at org.nutz.dao.impl.entity.AnnotationEntityMaker.make(AnnotationEntityMaker.java:90)
	at org.nutz.dao.impl.EntityHolder.getEntity(EntityHolder.java:72)
	at org.nutz.dao.impl.NutDao.getEntity(NutDao.java:682)
	at cn.wizzer.app.templet.modules.service.impl.PopulationServiceImpl.getAreaPersonStructure(PopulationServiceImpl.java:426)
sql.setCallback(Sqls.callback.maps());
Entity< Map> entity = dao().getEntity( Map.class);

这行报错,改了下面也没用

回调用maps(),不需要Entity!!!

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