NutzCN Logo
问答 如何使自定义的sql,可以把分页信息和json数据返回
发布于 2602天前 作者 qq_e3b6dba3 1419 次浏览 复制 上一个帖子 下一个帖子
标签:

public List demoSql(Integer cellId,Integer pageNum) {

        Sql sql = Sqls.create("SELECT  a.*,b.code FROM `tbl_cell_process_log` as a, tbl_cell as b where a.cell_id=@id and a.cell_id=b.idtbl_cell ORDER BY a.create_time desc");
        sql.params().set("id", cellId);
        final JSONArray json = new JSONArray();
        sql.setCallback(new SqlCallback() {

         public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
                List<String> list = new LinkedList<String>();

                while (rs.next()){
                   JSONObject jo = new JSONObject();
                    jo.put("user_type",rs.getString("user_type"));
                     jo.put("create_time", rs.getString("create_time"));
                     jo.put("process_code", rs.getString("process_code"));
                     jo.put("idtbl_cell_process_log_id", rs.getString("idtbl_cell_process_log_id"));
                     jo.put("powder_type", rs.getString("powder_type"));
                     jo.put("process_source", rs.getString("process_source"));
                     jo.put("cell_id", rs.getString("cell_id"));
                     jo.put("code", rs.getString("code"));
                    json.add(jo);
                    list.add(rs.getString("user_type"));
                    list.add(rs.getString("create_time"));
                    list.add(rs.getString("process_code"));
                    list.add(rs.getString("idtbl_cell_process_log_id"));
                    list.add(rs.getString("powder_type"));
                    list.add(rs.getString("process_source"));
                    list.add(rs.getString("cell_id"));
                    list.add(rs.getString("code"));


                    }

                return json;
            }

        });

        dao().execute(sql);
        return sql.getList(String.class);
        // Nutz内置了大量回调, 请查看Sqls.callback的属性
    }
1 回复
        Sql sql = Sqls.create("SELECT  a.*,b.code FROM `tbl_cell_process_log` as a, tbl_cell as b where a.cell_id=@id and a.cell_id=b.idtbl_cell ORDER BY a.create_time desc");
        sql.params().set("id", cellId);
        Pager pager = new Pager(pageNum);
        sql.setPager(pager);
        sql.setCallback(Sqls.callback.maps());

        dao().execute(sql);
        List<Map> maps = sql.getList(Map.class);
        return new QueryResult(maps, pager);

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