zoukankan      html  css  js  c++  java
  • 项目笔记:导入功能

      前台JS:注意:url后的  ?disc=baseLineTemplate  是必须要加的,因为要走先处理一下

    var serialNumberUrl = "";
        $(function() {
            $("#buttonSubmit").bind("click", function() {
                var serialNumberFileVal = $("#serialNumberFile").val();
                serialNumberFileVal = serialNumberFileVal.substring(serialNumberFileVal.lastIndexOf('.') + 1);
                if (serialNumberFileVal != "xml") {
                    showAlertDialog("提示", "请选择xml文件上传");
                    return false;
                } else {
                    serialNumberUrl = "${basePath}/genuineSerialNumberManagementAction_importSerialNumber.do?disc=baseLineTemplate";
                    document.serialNumber_importSerialNumber.action = serialNumberUrl;
                    serialNumber_importSerialNumber.submit();
                }
            });
             /** 验证文件是否导入成功  */  
            $("#serialNumber_importSerialNumber").ajaxForm(function(data){
                setMessage(data);
            });
        });

      后台解析数据:

    //导入模板
    public void importSerialNumber(){
        this.msg = RESULT_ERROR;
        try{
            // 记录文件上传的MAP对象
            User currentUser = SessionUtil.getInstance().getUserFromSession(this.getRequest());
            final String name = currentUser.getAccount().trim();// 加入实际项目后,获取文件上传的系统用户名称,即登录用记名称,唯一性
            for (Entry<String, String[]> entry : FileUploadConstant.fileOperator_baseTemplate.entrySet()) {
                File file = new File(entry.getValue()[1]);
                this.msg = genuineSerialNumberManagementService.importTemplate(file);
                FileUploadConstant.fileOperator_baseTemplate.remove(entry.getKey());
            }
            FileUploadConstant.fileOperator_baseTemplate.clear();
            genuineSerialNumberManagementService.createXML();
        }catch(Exception e){
            log.error("导入规则库失败!", e);
            this.msg = RESULT_ERROR;
        }
        print(this.msg);
    }
    public String importTemplate(File file) {
        String message = "error";
        try {
            //获取文件
            Document doc = XMLUtil.getDocument(file.getPath());
            // 获取根节点
            Element root = doc.getRootElement();
            //根据根节点判断type值
            Integer type = null;
            if("SoftLicW".equals(root.getQName().getName())){
                type = 1;
            }else if("SoftLicB".equals(root.getQName().getName())){
                type = 0;
            }
            // 获取Software节点
            Iterator<?> ruleNode = root.elementIterator("Software");
            // 循环Software节点,判断是否存在
            while (ruleNode.hasNext()) {
                Element ruleElement = (Element) ruleNode.next();
                Attribute ruleXmlId = ruleElement.attribute("SoftId");
                Attribute ruleXmlName = ruleElement.attribute("DisplayName");
                // 获取license节点
                Iterator<?> license = ruleElement.elementIterator("license");
                // 循环license节点,判断是否存在
                while (license.hasNext()) {
                    Element licenseElement = (Element) license.next();
                    Attribute licenseVersion = licenseElement.attribute("Version");
                    Attribute licenseValue = licenseElement.attribute("value");
                    GenuineSerialNumberManagement serialNumber = new GenuineSerialNumberManagement();
                    serialNumber.setType(type);
                    serialNumber.setSoftId(Integer.valueOf(ruleXmlId.getText()));
                    serialNumber.setSoftDisplayName(ruleXmlName.getText());
                    serialNumber.setVersion(licenseVersion.getText());
                    serialNumber.setSerialNumber(licenseValue.getText());
                    genuineSerialNumberManagementDao.save(serialNumber);//保存解析出来的数据到数据库
                }
            }
            message = "success";
        } catch (Exception e) {
            e.printStackTrace();
            message = "error";
        }
        return message;
    }
  • 相关阅读:
    解决点击链接自动置顶问题
    ie6 下遮罩层 height 不显示100%的解决方法
    【转帖】微软分布式缓存框架Volocity资源推荐
    Tips 2 MVC实现多个按钮提交的几种方法
    .NET Framework 4 中的新增功能
    Memcached 汇总 不断更新
    理解敏捷Agile
    GPIOPS中断成功,问题仍旧存在 ZEDBOARD,ZYNQ7000
    Xilinx驱动API的一个重要BUG,ZEDBOARD,ZYNQ7000
    RelativeLayout相对布局
  • 原文地址:https://www.cnblogs.com/goloving/p/7553776.html
Copyright © 2011-2022 走看看