easyui 表格展示接口查到的数据

后台代码块 调用的全国油价接口

@RequestMapping("queryhttps")
@ResponseBody
public   String   queryhttps(){
    CloseableHttpClient httpclient= HttpClients.createDefault();

    ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

    CloseableHttpResponse response = null;
    String userJson = "";
    HttpGet httpGet = null;
     try {
        String  paramsStr = EntityUtils.toString(new UrlEncodedFormEntity(params, Consts.UTF_8));
          httpGet = new HttpGet("http://apis.juhe.cn/cnoil/oil_city?key=be0660baf9654b8d04f4786ea3233f15");
          httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1;"
                    + " Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0");
          httpGet.setHeader("Accept", "application/json");

          httpGet.setHeader("Accept-Encoding", "gzip, deflate");
          httpGet.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
         RequestConfig config = RequestConfig.custom()
                    .setConnectTimeout(10000)       //设置链接超时的时间1秒钟
                    .setSocketTimeout(10000)        //设置读取超时1秒钟
                    .build();                       //RequestConfig静态方法  setProxy  设置代理
        httpGet.setConfig(config);

        response = httpclient.execute(httpGet);

        userJson = EntityUtils.toString(response.getEntity(), "UTF-8");


     } catch (ParseException | IOException e) {
         e.printStackTrace();
    }finally{
        try {
            httpclient.close();
            response.close();
            httpGet.abort();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }       

    return  userJson;
}

userJson  查询到的数据

{"resultcode":"200","reason":"查询成功!","result":[{"city":"北京","b90":"6.75","b93":"7.54","b97":"8.03","b0":"7.23"},{"city":"天津","b90":"6.67","b93":"7.54","b97":"7.96","b0":"7.18"},{"city":"河北","b90":"5.61","b93":"7.54","b97":"7.96","b0":"7.18"},{"city":"山西","b90":"5.64","b93":"7.49","b97":"8.09","b0":"7.25"},{"city":"内蒙古","b90":"","b93":"7.50","b97":"8.05","b0":"6.99"},{"city":"辽宁","b90":"5.86","b93":"7.51","b97":"8.10","b0":"7.10"},{"city":"吉林","b90":"6.10","b93":"7.51","b97":"8.10","b0":"7.10"},{"city":"黑龙江","b90":"","b93":"7.40","b97":"7.90","b0":"6.95"},{"city":"上海","b90":"6.62","b93":"7.51","b97":"7.99","b0":"7.16"},{"city":"江苏","b90":"6.66","b93":"7.51","b97":"7.99","b0":"7.14"},{"city":"浙江","b90":"5.99","b93":"7.51","b97":"7.99","b0":"7.16"},{"city":"安徽","b90":"6.37","b93":"7.50","b97":"8.03","b0":"7.22"},{"city":"福建","b90":"5.62","b93":"7.51","b97":"8.02","b0":"7.17"},{"city":"江西","b90":"6.60","b93":"7.50","b97":"8.06","b0":"7.23"},{"city":"山东","b90":"5.54","b93":"7.52","b97":"8.07","b0":"7.18"},{"city":"河南","b90":"5.68","b93":"7.55","b97":"8.06","b0":"7.17"},{"city":"湖北","b90":"5.40","b93":"7.55","b97":"8.09","b0":"7.17"},{"city":"湖南","b90":"6.64","b93":"7.49","b97":"7.97","b0":"7.25"},{"city":"广东","b90":"","b93":"7.56","b97":"8.19","b0":"7.19"},{"city":"广西","b90":"5.45","b93":"7.60","b97":"8.21","b0":"7.24"},{"city":"海南","b90":"7.61","b93":"8.66","b97":"9.19","b0":"7.27"},{"city":"重庆","b90":"6.53","b93":"7.61","b97":"8.04","b0":"7.25"},{"city":"四川","b90":"6.12","b93":"7.57","b97":"8.15","b0":"7.27"},{"city":"贵州","b90":"6.94","b93":"7.67","b97":"8.11","b0":"7.29"},{"city":"云南","b90":"6.70","b93":"7.69","b97":"8.25","b0":"7.25"},{"city":"西藏","b90":"7.23","b93":"8.42","b97":"8.91","b0":"7.72"},{"city":"陕西","b90":"5.67","b93":"7.43","b97":"7.85","b0":"7.08"},{"city":"甘肃","b90":"5.51","b93":"7.43","b97":"7.94","b0":"7.08"},{"city":"青海","b90":"5.85","b93":"7.50","b97":"8.04","b0":"7.11"},{"city":"宁夏","b90":"5.56","b93":"7.45","b97":"7.87","b0":"7.07"},{"city":"新疆","b90":"6.06","b93":"7.33","b97":"7.88","b0":"6.99"}],"error_code":0}

//初始化查询
$(function(){

   $('#tableId').datagrid({    
        url:'<%=request.getContextPath()%>/httpclient/queryhttps.do',


    }); 

});

easyui 表格怎么展示

2个回答

搞半天你是前台不会展示。。。。
列子:

 dataGrid = $('#tableId')
                .datagrid(
                        {
                            loadMsg : '数据加载中....',
                            url : 'sdCstmInfoController.do?queryhttps',       //找到对应Controller类,然后调用方法
                            fit : true,
                            fitColumns : false,
                            border : false,
                            pagination : true,
                            idField : 'id',
                            pageSize : 10,
                            pageList : [ 10, 20, 30, 40, 50 ],
                            sortName : 'id',
                            sortOrder : 'desc',
                            checkOnSelect : false,
                            selectOnCheck : false,
                            nowrap : true,
                            rownumbers : true,
                            border : true,
                            striped : true,
                            singleSelect : true,
                            columns : [[
                                    {
                                        field : 'id',
                                        title : '',
                                        width : 150,
                                        checkbox : true
                                    },
                                    {
                                        field : 'cstmName',
                                        title : '姓名',
                                        width : 100,
                                        sortable : true

                                    },{
                                        field : 'changeType',
                                        title : '变更类型',
                                        width : 100,
                                        sortable : true,
                                        formatter : function(value, row) {
                                            if (1 == value)
                                                //return "<strong style='color:blue;' >信息变更</strong>";

                                                return "<strong style='color:green'>信息变更</strong>";

                                            else if (2 == value)
                                                //return "<strong style='color:red;'>死亡申报</strong>";
                                                return "<strong style='color:red'>死亡申报</strong>";
                                            else return "";
                                        }
                                    },   
                                    {
                                        field : 'deathState',
                                        title : '是否正常死亡',
                                        width : 100,
                                        sortable : true,
                                        formatter : function(value, row) {
                                            if ("1" == value)
                                                return "<strong style='color:blue'>是</strong>";
                                            else if ("2" == value)
                                                return "<strong style='color:blue'>否</strong>";   
                                                else return "";
                                        }
                                    },
                                    {
                                        field : 'deathTime',
                                        title : '死亡时间',
                                        width : 100,
                                        sortable : true,
                                        formatter : function(value, row) {
                                               if(value!=null)
                                                {
                                                   return value.substring(0,10);
                                                }else{
                                                     return "";}
                                        }
                                    },
                                    {
                                        field : 'deathMemo',
                                        title : '死亡原因',
                                        width : 160,
                                        sortable : true,                                    
                                    },

                                    {
                                        field : 'operat',
                                        title : '操作',
                                        halign: 'center',
                                        width : 180,
                                        sortable : true,
                                        formatter : function(value, row) {
                                            if ("1" == row.auditState)
                                                  if(row.deathProve!="")
                                                      {
                                                         return '<a href="javascript:void(0);" class="edit_button" iconCls="icon-edit"  onclick="updateInformat(\'' + row.id + '\')"></a> <a href="javascript:downfile('+row.id+')" class="down_button" iconCls="icon-edit" target="_blank"/>'  
                                                      }else{
                                                          return '<a href="javascript:void(0);" class="edit_button" iconCls="icon-edit"  onclick="updateInformat(\'' + row.id + '\')"></a> '    
                                                      }
                                            if ("3" == row.auditState)
                                                if(row.deathProve!="")
                                                  {
                                                     return '<a href="javascript:void(0);" class="edit_button" iconCls="icon-edit"  onclick="updateInformat(\'' + row.id + '\')"></a> <a href="javascript:downfile('+row.id+')" class="down_button" iconCls="icon-edit" target="_blank"/>'  
                                                  }else{
                                                      return '<a href="javascript:void(0);" class="edit_button" iconCls="icon-edit"  onclick="updateInformat(\'' + row.id + '\')"></a> '    
                                                  }
                                            if ("2" == row.auditState)
                                                if(row.deathProve!=""){
                                                    return '<a href="javascript:downfile('+row.id+')" class="down_button" iconCls="icon-edit" target="_blank"/>'    
                                                }


                                        }
                                    },
                                    {
                                        field : 'auditState',
                                        title : '审核状态',
                                        width : 100,
                                        sortable : true,
                                        formatter : function(value, row) {
                                            if (1 == value)
                                                return "<strong style='color:blue'>未审核</strong>";
                                            else if (2 == value)
                                                return "<strong style='color:green'>审核通过</strong>";
                                            else if (3 == value)
                                                return "<strong style='color:red'>审核不通过</strong>";    
                                                else return "";
                                        }
                                    },{
                                        field : 'auditName',
                                        title : '审核人',
                                        width : 100,
                                        sortable : true                                 
                                    }
                                    ,{
                                        field : 'auditMemo',
                                        title : '审核备注',
                                        width : 150,
                                        sortable : true                                 
                                    },{
                                        field : 'auditTime',
                                        title : '审核时间',
                                        width : 90,
                                        sortable : true,
                                        formatter : function(value, row) {
                                               if(value!=null)
                                                {
                                                   return value.substring(0,10);
                                                }else{
                                                     return "";}
                                        }
                                    }
                                     ] ],
                            toolbar : '#toolbar',
                            onLoadSuccess : function(rowData) {
                                $(".edit_button").linkbutton({
                                    text : '修改',
                                    plain : true,
                                    iconCls : 'icon-edit'
                                });
                                $(".delete_button").linkbutton({
                                    text : '删除',
                                    plain : true,
                                    iconCls : 'icon-delete'
                                });
                                $(".save_button").linkbutton({
                                    text : '附件下载',
                                    plain : true,
                                    iconCls : 'icon-save'
                                });
                                $(".down_button").linkbutton({
                                    text: '附件下载',
                                    plain: true,
                                    iconCls: 'icon-download'
                                });
                                doCellTips(true);
                                $('#dataGrid').datagrid('clearSelections');
                            },
                            onRowContextMenu : function(e, rowIndex, rowData) {
                                e.preventDefault();
                                $(this).datagrid('unselectAll').datagrid(
                                        'uncheckAll');
                                $(this).datagrid('selectRow', rowIndex);
                                $('#menu_tools').menu('show', {
                                    left : e.pageX,
                                    top : e.pageY
                                });
                            }
                        });
qq_43198047
qq_43198047 回复qq_23126581: 以前做的都是自己的数据 不需要做处理 field 就可以直接展示的
一年多之前 回复
qq_43198047
qq_43198047 回复qq_23126581: {"resultcode":"200","reason":"查询成功!","result": 主要是这一块没整明白 怎么做处理 field 没法识别这个
一年多之前 回复
qq_23126581
渊渟无迹静涛君 field 这个就是你json数据里对应的字段名了,比如city b90
一年多之前 回复

你需要先处理你返回的json数据。比如查用Listlist一样。直接把这个list打包就可以了,你那个数据,需要把其他数据去掉,只剩余result里数据

qq_23126581
渊渟无迹静涛君 回复qq_23126581: 别急
一年多之前 回复
qq_23126581
渊渟无迹静涛君 你一步一步试试吧,做出来你就会有成就感
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐