当前位置:   article > 正文

JAVA编码(15)——使用FRAMEMARK创建XML

JAVA编码(15)——使用FRAMEMARK创建XML
  1. 首先需要导入freemarker-2.3.19.jar包
  2. 然后穿件一个xml文件模板
  3. 再次:
  4. Map root= new HashMap();
  5. for (int i = 0; i < listborrownum.size(); i++) {//生成借的凭证
  6. voucherborrow = new VoucherEntrySchema();
  7. voucherborrow.setId(i+1);
  8. voucherborrow.setPayDate(payDate);
  9. voucherborrow.setObjectinfo(listborrownum.get(i).getObjectinfo());
  10. voucherborrow.setPayMoney1(listborrownum.get(i).getPayMoney1());
  11. listborrow.add(voucherborrow);
  12. }
  13. for (int i = 0; i < listcreditnum.size(); i++) {//生成贷的凭证对象
  14. vouchercredit = new VoucherEntrySchema();
  15. vouchercredit.setId(i+2);
  16. vouchercredit.setPayDate(payDate);
  17. vouchercredit.setObjectinfo(listcreditnum.get(i).getObjectinfo());
  18. vouchercredit.setPayMoney2(listcreditnum.get(i).getPayMoney2());
  19. listcredit.add(vouchercredit);
  20. }
  21. root.put("currentMills", "ZJ"+System.currentTimeMillis());//当前时间的毫秒数
  22. root.put("currentDate", currentDate);//当前的日期
  23. root.put("number", number);//生成 entry 的总记录数
  24. root.put("entryborrow", listborrow);
  25. root.put("entrycredit", listcredit);
  26. Configuration config = new Configuration();
  27. URL url=Thread.currentThread().getContextClassLoader().getResource("CreateVoucher.ft");
  28. temp=url.getFile();
  29. temp=temp.substring(1,temp.length());
  30. temp=temp.substring(0,temp.lastIndexOf("/"));
  31. config.setDirectoryForTemplateLoading(new File(temp));
  32. config.setObjectWrapper(new DefaultObjectWrapper());
  33. Template t = config.getTemplate("CreateVoucher.ft");
  34. String currentTime = current.replaceAll("-","");
  35. InputStream in = null;
  36. FileOutputStream fos = null;
  37. File file = null;
  38. String voucher1 = LoadLocationProperties.getPropertiesValue("/location.properties", "voucher1");
  39. try {
  40. System.out.println(voucher1);
  41. file=new File(voucher1+"999999999_"+currentTime+"_LNAE_"+System.currentTimeMillis()+"_"+(Math.random()+"").substring(2)+".xml");
  42. file.getParentFile().mkdirs();
  43. if(!file.exists()){
  44. file.createNewFile();
  45. }
  46. fos = new FileOutputStream(file);
  47. PrintWriter writer = new PrintWriter(fos);
  48. t.process(root, writer);
  49. listborrow.remove(voucherborrow);
  50. listcredit.remove(vouchercredit);
  51. } catch (Exception e) {
  52. e.printStackTrace();
  53. }finally{
  54. fos.flush();
  55. fos.close();

  

转载于:https://www.cnblogs.com/xushuyi/articles/4394549.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/617083
推荐阅读
相关标签
  

闽ICP备14008679号