邮件加载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
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); } }