• properties文件导出


      功能要求根据数据库记录的key-value-remark 数据,导出保存properties文件

      1. pro.load()  pro.list() 处理不能解决备注、排序问题

      2. 最后考虑下什么是properties文件,操作系统大概怎么区分这样的数据是正确的properties数据,区分大概回车符与#符,直接拼接字符,输入输出流导出

          

    @RequestMapping(value = "/export/{id}", method = RequestMethod.GET)
        public void export(@PathVariable("id") Long id) throws IOException {
            response.reset();
            StringBuilder buff = new StringBuilder();
        
            AppProperties tc = appPropertiesService.get(id);
            String fileName = tc.getLineCode()+tc.getAppCode()+tc.getId();
            if(tc != null){
                Collection<SearchFilter> filters = new ArrayList<>();
                filters.add(new SearchFilter("refId",SearchFilter.Operator.valueOf("EQ"),id));
                List<PropertiesInfo> detailList = propertiesInfoService.findAll(new SearchSpecification(filters,PropertiesInfo.class) , new Sort(Sort.Direction.ASC,new String[]{"orderBy"}));
                for(PropertiesInfo info:detailList){
                    if(info.getRemark() != null && !"".equals(info.getRemark())){
                        buff.append("#").append(info.getRemark()).append("
    ");
                    }
                    buff.append(info.getKey()).append("=").append(info.getValue()).append("
    ");
                    
                }
            } 
    
            response.setHeader("Content-Disposition", "attachment;filename="+fileName+".properties");
            response.setContentType("application/msexcel; charset=GBK");
            ServletOutputStream out = response.getOutputStream();
            
            BufferedInputStream br = new BufferedInputStream(new ByteArrayInputStream(buff.toString().getBytes()));  
            byte[] buf = new byte[1024];
            int len = 0;   
    
            while ((len = br.read(buf)) > 0){
                out.write(buf, 0, len);  
            }  
            out.flush();
            br.close(); 
            out.close();
    
        }

      

      

  • 相关阅读:
    如何将Python项目发布到PyPI
    hashlib的md5计算
    使用hexo和coding建立静态博客站点
    mysql 使用记录
    linux QA
    linux 使用记录
    转载-linux内核长什么样
    mysql 更改默认字符集
    Say goodbye
    SSH proxycommand 不在同一局域网的机器ssh直连
  • 原文地址:https://www.cnblogs.com/ks-apper/p/5157817.html
Copyright © 2020-2023  润新知