• dom4j解析xml


    @RequestMapping("/getGridColumn")
        public void getGridColumn(HttpServletRequest request,HttpServletResponse response,String model) throws Exception{
            //xml存在web-inf目录下
            String filePath = request.getSession().getServletContext().getRealPath("/WEB-INF")+"/columnName.xml";
            Map<String, Object> map = new HashMap<String, Object>();
            SAXReader reader = new SAXReader();
            Document doc = reader.read(new File(filePath));
            Element root = doc.getRootElement();
            Iterator<?> iters = root.elementIterator("column");
            while(iters.hasNext()){
                Element column = (Element)iters.next();
                //取得column节点的名称
                String columnName = column.attributeValue("name");
                if(columnName!=null && columnName.equals(model)){
                    List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
                    map.put("className", columnName);
                    map.put("isMultiple", column.attributeValue("isMultiple"));
                    Iterator<?> items = column.elementIterator("item");
                    //设置行号
                    Map<String, Object> columnNumber = new HashMap<String, Object>();
                    columnNumber.put("text", "行号");
                    columnNumber.put("xtype", "rownumberer");
                    columnNumber.put("align", "center");
                    columnNumber.put("width", 40);            
                    list.add(columnNumber);
                    while(items.hasNext()){
                        Element item = (Element)items.next();                
                        Map<String, Object> itemMap = new HashMap<String, Object>();
                        itemMap.put("dataIndex",item.attributeValue("name"));
                        itemMap.put("text",item.attributeValue("value"));
                        int width = 128;
                        if(item.attributeValue("width")!=null && !item.attributeValue("width").equals("")){
                            width = Integer.parseInt(item.attributeValue("width"));
                        }
                        if(item.attributeValue("hidden")!=null && !item.attributeValue("hidden").equals("")){
                            if(item.attributeValue("hidden").equals("true")){
                                itemMap.put("hidden",true);
                            }    
                        }
                        List<Map<String, Object>> renderersList = new ArrayList<Map<String,Object>>();
                        @SuppressWarnings("unchecked")
                        List<Element> renderers = item.elements("renderer");
                        if(renderers!=null && renderers.size()>0){
                            for(Element renderer : renderers){
                                Map<String, Object> rendererMap = new HashMap<String, Object>();
                                rendererMap.put("name",renderer.attributeValue("name"));
                                rendererMap.put("value",renderer.attributeValue("value"));
                                if(renderer.attributeValue("color")!=null && !renderer.attributeValue("color").equals("")){
                                    rendererMap.put("color",renderer.attributeValue("color"));
                                }
                                renderersList.add(rendererMap);
                            }
                        }
                        itemMap.put("width",width);
                        itemMap.put("align","center");
                        if(renderersList.size()>0){
                            itemMap.put("renderers",renderersList);
                        }
                        list.add(itemMap);
                    }
                    map.put("columns", list);
                    //如果找到和Model匹配的名称则跳出循环
                    break;
                }
            }
            Gson gson = new Gson();
            outPrint.printSting(request, response,true, gson.toJson(map));
        }
  • 相关阅读:
    A Simple Problem with Integers-POJ3468 区间修改+区间查询
    致橡树
    OJ-Triangle
    Myeclipse+AJAX+Servlet
    opnet学习过程
    yii2在ubuntu下执行定时任务
    php创建文件夹后设置文件夹权限(转)
    “Request Entity Too Large” 上传图片出现大小限制
    慕课网,我的yii2学习笔记(基础篇)
    Yii2高级版本复制新项目出现问题解决(转)
  • 原文地址:https://www.cnblogs.com/zhougaojun/p/3624008.html
Copyright © 2020-2023  润新知