public static String render(String templateContent, Map<String, Object> paramMap) {
        StringWriter writer = new StringWriter();
        try {
            Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
            cfg.setTemplateLoader(new StringTemplateLoader(templateContent));
            cfg.setDefaultEncoding("UTF-8");

            Template template = cfg.getTemplate("");

            template.process(paramMap, writer);
        } catch (IOException e) {
            e.printStackTrace();
            log.error(e.getMessage());
        } catch (TemplateException e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return writer.toString();
    }
public static String render(String templateContent, Map<String, Object> paramMap) {
        StringWriter writer = new StringWriter();
        try {
            Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
            cfg.setTemplateLoader(new StringTemplateLoader(templateContent));
            cfg.setDefaultEncoding("UTF-8");

            Template template = cfg.getTemplate("");

            template.process(paramMap, writer);
        } catch (IOException e) {
            e.printStackTrace();
            log.error(e.getMessage());
        } catch (TemplateException e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return writer.toString();
    }
public static String render ( String templateContent , Map < String , Object > paramMap ) { StringWriter writer = new StringWriter ( ) ; try { Configuration cfg = new Configuration ( Configuration . VERSION_2_3_22 ) ; cfg . setTemplateLoader ( new StringTemplateLoader ( templateContent ) ) ; cfg . setDefaultEncoding ( "UTF-8" ) ; Template template = cfg . getTemplate ( "" ) ; template . process ( paramMap , writer ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; log . error ( e . getMessage ( ) ) ; } catch ( TemplateException e ) { e . printStackTrace ( ) ; log . error ( e . getMessage ( ) ) ; } return writer . toString ( ) ; }
渲染模板
渲染模板