spring下配置一个新的velocity engine


applicatioin-context.xml

	
		
			
				file
				.
				
					org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
				
				UTF-8
				UTF-8
			
		
	

invite_email.vm


$name
$content

Test

	@Test
	public void testMergeTemplateIntoString() {
		Map map = new HashMap();
		map.put("name", "张三");
		map.put("content", "This is content!!!");
		map.put("img", "http://www.iknowing.com/photos/1/1/1.jpg");
		
		String vm = "invite_email.vm";
		
		String html = templateService.mergeTemplateIntoString(vm, map);
		System.out.println(html);
	}

TemplateService

private static String tplFolder = "templates/";
	
	@Autowired
	private VelocityEngine velocityEngine;
	
	@Override
	public String mergeTemplateIntoString(String vm, Map map) {
		String tpl = tplFolder + vm;
		return VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, tpl, map);
	}



你可能感兴趣的:(spring下配置一个新的velocity engine)