freemarker 小例证

freemarker 小例子




public void test(){
		 Configuration cfg = new Configuration();
		 cfg.setClassForTemplateLoading(getClass()  , "");
		 cfg.setObjectWrapper(new DefaultObjectWrapper());  
 		 Map<String, Object> goods = new HashMap<String, Object>();
//		 goods.put("name", "kingapex");
		 List list= new ArrayList();
		 list.add("1");
		 list.add("2");
		 list.add("3");
		 goods.put("nlist", list);
		 
		 try {
			Template temp = cfg.getTemplate("goodslist.html");
			ByteOutputStream stream = new ByteOutputStream();
			Writer out = new OutputStreamWriter(stream);
			temp.process(goods, out);
			out.flush();  
			String name =this.getClass().getName();
			name = name.substring(name.lastIndexOf('.')+1);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (TemplateException e) {
			e.printStackTrace();
		}
	}







1 楼 jiana227 2012-05-07  
楼主可以把参数的详解也贴出来么