306°

SpringBoot使用Freemaker模板生成内容

先注入

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
@Autowired
private FreeMarkerConfigurer freeMarkerConfigurer;
 private String render(String templateName, Map<String, Object> model) {
        try {
            Template t = freeMarkerConfigurer.getConfiguration().getTemplate(templateName, "UTF-8");
            t.setOutputEncoding("UTF-8");
            return FreeMarkerTemplateUtils.processTemplateIntoString(t, model);
        } catch (Exception e) {
            throw new MtonsException(e.getMessage(), e);
        }
    }

 

全部评论: 0

    我有话说: