NutzCN Logo
问答 根据别名返回实体为null
发布于 2867天前 作者 SwainHo 2086 次浏览 复制 上一个帖子 下一个帖子
标签:
 public NutMap order(int length, int start, int draw, List<DataTableOrder> orders, List<DataTableColumn> columns, Cnd cnd, String linkname) {
        NutMap map = new NutMap();
        if (orders != null && orders.size() > 0) {
            for (DataTableOrder order : orders) {
                DataTableColumn col = columns.get(order.getColumn());
                cnd.orderBy(Sqls.escapeSqlFieldValue(col.getData()).toString(), order.getDir());
            }
        }
        Pager pager = new OffsetPager(start, length);
        Sql sql = Sqls.queryRecord("select a.id,a.number,a.time,a.status,a.pay_type," +
                "b.id,b.course_id,b.price,b.orig," +
                "c.id,c.name from edu_order a " +
                "left join edu_course_order b on a.id = b.order_id " +
                "left join edu_course c on b.course_id = c. id " +
                " $condition");

        sql.setCondition(cnd);
        sql.setPager(pager);
        dao().execute(sql);
        List<Edu_order> order=new ArrayList<>();
        List<Edu_course_order> courseOrder=new ArrayList<>();
        List<Edu_course> course=new ArrayList<>();
        List<Record> list = sql.getList(Record.class);
        for (Record re : list) {
            Edu_order o = re.toEntity(dao().getEntity(Edu_order.class),"a.");
            Edu_course_order co=re.toEntity(dao().getEntity(Edu_course_order.class),"b.");
            Edu_course c=re.toEntity(dao().getEntity(Edu_course.class),"c.");
            order.add(o);
            courseOrder.add(co);
            course.add(c);
        }
        //一级表项 订单总览
        map.put("order",order);
        //次级表项 订单详情
        map.put("courseOrder",courseOrder);
        map.put("course",course);
        map.put("draw", draw);
        map.put("recordsTotal", length);
        return map;

    }
    Edu_order o = re.toEntity(dao().getEntity(Edu_order.class),"a.");
        Edu_course_order co=re.toEntity(dao().getEntity(Edu_course_order.class),"b.");
        Edu_course c=re.toEntity(dao().getEntity(Edu_course.class),"c.");

这么写或者“a_”这样取得都是null 如果不用别名可以 但是查的字段有冲突所有的id这个一个都是一样的
是我写的格式不对吗

2 回复
select a.id as a_id,a.number as a_number 

然后按前置a_取出

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