功能要求根据数据库记录的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("\r");
                }
                buff.append(info.getKey()).append("=").append(info.getValue()).append("\r");
                
            }
        } 

        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();

    }

 

  

  

 

posted on 2016-01-25 16:29  惋红曲  阅读(137)  评论(0编辑  收藏  举报