当前位置 : 主页 > 编程语言 > java >

加载freemarker模板

来源:互联网 收集:自由互联 发布时间:2021-06-28
邮件加载freemarker模板 package test;import java.util.HashMap;import java.util.Map;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.test.cont
邮件加载freemarker模板
package test;

import java.util.HashMap;
import java.util.Map;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;

import com.jspxcms.core.domain.User;

import freemarker.template.Configuration;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:conf/context-application.xml", "classpath:custom.xml",
		"classpath:conf/servlet-fore.xml" })
public class freemarkerTest {

	@Autowired
	private Configuration freemarkerConfiguration;

	@Test
	public void mailTemplate() {
		StringBuffer content = new StringBuffer();
		Map
 
   model = new HashMap<>();
		User u = new User();
		u.setUsername("实体测试啦");
		model.put("bean", u);
		try {
			content.append(FreeMarkerTemplateUtils.processTemplateIntoString(
					freemarkerConfiguration.getTemplate("itvsa_apply_user.html"), model));
		} catch (Exception e) {
			e.printStackTrace();
		} 
		System.out.println(content);
	}
}
 
配置文件
网友评论