freemaker

project文件内又一个变量 ${pro_name.full }


  1. private static Configuration cfg = new Configuration(); 
  2.     public static void generateFile() throws IOException{ 
  3.         Map <String, String> map = new HashMap<String, String>(); 
  4.         map.put("pro_name.full", "项目名"); 
  5.         cfg.setDefaultEncoding("UTF-8"); 
  6.         cfg.setDirectoryForTemplateLoading(new File("D:\\")); 
  7. Template template = cfg.getTemplate(".project"); 
  8.         String tofile = "D:\\.project"
  9.         FileOutputStream fos = new FileOutputStream(tofile); 
  10.         OutputStreamWriter osw = new OutputStreamWriter(fos,"utf-8"); 
  11.  
  12.         try
  13.             template.process(map, osw); 
  14.         } catch (TemplateException e) { 
  15.         } finally
  16.             osw.close(); 
  17.         } 
  18.     } 
private static Configuration cfg = new Configuration();
	public static void generateFile() throws IOException{
		Map <String, String> map = new HashMap<String, String>();
		map.put("pro_name.full", "项目名");
		cfg.setDefaultEncoding("UTF-8");
		cfg.setDirectoryForTemplateLoading(new File("D:\\"));
		Template template = cfg.getTemplate(".project");
		String tofile = "D:\\.project";
		FileOutputStream fos = new FileOutputStream(tofile);
		OutputStreamWriter osw = new OutputStreamWriter(fos,"utf-8");

		try {
			template.process(map, osw);
		} catch (TemplateException e) {
		} finally {
			osw.close();
		}
	}


运行后会发现原来的变量,变成了项目名。


freemaker是一个非常不错的框架。由于实习公司用的这个现在不是特别清楚了,回顾回顾

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值