NutzCN Logo
问答 java.lang.ClassCastException:
发布于 2906天前 作者 果粉 2086 次浏览 复制 上一个帖子 下一个帖子
标签:

List list= this.recursive(id);
System.out.print("list:"+list);
for (int i=0; i<list.size(); i++){
list.get(i); //正常
System.out.print("list.get(i):"+list.get(i));

       list.get(i).getId();                                       //报异常
       list.get(i).getName();
    }

java.lang.ClassCastException: org.nutz.dao.entity.Record cannot be cast to cn.bphc.domain.User

6 回复

问题在 this.recursive方法

public List<User>  recursive(String id){
    Sql sql=Sqls.create("SELECT * FROM User  START WITH id = @id  CONNECT BY PRIOR PARENT_ID = id");
    sql.setCallback(Sqls.callback.records());
    sql.setParam("id", id);
    dao().execute(sql);
    return sql.getList(User.class);
}

不能这样调吗 this.recursive

@qq_05da7e3c

sql.setCallback(Sqls.callback.entites());
sql.setEntity(dao.getEntity(User.class));

list:[{
"id": "762ea315543640f59eddd169b32597dc",
"create_date": "2016-11-28 17:19:31",
"modify_date": "2016-11-28 17:19:31",
"grade": 0,
"name": "李持缨",
"order_id": 6,
"parent_id": "c417b4c62c004188aa7cfa1956b90edd",
"tree_path": null,
"is_menu": "1",
"url": null,
"allow_article": "1",
"menu_type": 1,
"old_name": null
}, {
"id": "c417b4c62c004188aa7cfa1956b90edd",
"create_date": "2016-11-29 21:59:28",
"modify_date": "2016-11-29 21:59:28",
"grade": 1,
"name": "中心领导",
"order_id": 1,
"parent_id": "ed60c5760e684f9ab4113698c9a2c5d4",
"tree_path": "ed60c5760e684f9ab4113698c9a2c5d4",
"is_menu": "1",
"url": null,
"allow_article": "1",
"menu_type": 1,
"old_name": null
}, {
"id": "ed60c5760e684f9ab4113698c9a2c5d4",
"create_date": "2016-11-28 16:25:04",
"modify_date": "2016-11-28 16:25:04",
"grade": 0,
"name": "市投资公司",
"order_id": 1,
"parent_id": null,
"tree_path": null,
"is_menu": "1",
"url": null,
"allow_article": "1",
"menu_type": 1,
"old_name": null
}]list.get(i):{
"id": "762ea315543640f59eddd169b32597dc",
"create_date": "2016-11-28 17:19:31",
"modify_date": "2016-11-28 17:19:31",
"grade": 0,
"name": "李持缨",
"order_id": 6,
"parent_id": "c417b4c62c004188aa7cfa1956b90edd",
"tree_path": null,
"is_menu": "1",
"url": null,
"allow_article": "1",
"menu_type": 1,
"old_name": null
}

点属性取值,就抛这个异常了

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