freemarker中ftl文件,中文乱码解决方法

如果是在java中配置,其配置为:

properties.setProperty("locale","utf-8");

properties.setProperty("default_encoding","utf-8");

所有配置如下:

@Bean
public FreeMarkerConfigurer freeMarkerConfigurer() {
    FreeMarkerConfigurer freeMarkerConfigurer;
    freeMarkerConfigurer = new FreeMarkerConfigurer();
    freeMarkerConfigurer.setTemplateLoaderPath("WEB-INF/freemarker");

    Properties properties = new Properties();
    properties.setProperty("number_format", "#.##");
    properties.setProperty("datetime_format","yyyy-MM-dd HH:mm:ss");
    properties.setProperty("time_format","HH:mm:ss");
    properties.setProperty("boolean_format","true,false");
    properties.setProperty("whitespace_stripping","true");
    properties.setProperty("locale","utf-8");
    properties.setProperty("default_encoding","utf-8");
    properties.setProperty("template_update_delay","5");
    properties.setProperty("output_format", "HTMLOutputFormat");
    freeMarkerConfigurer.setFreemarkerSettings(properties);

    Map variables = new HashMap<>();
    variables.put("xml_escape", new XmlEscape());
    variables.put("html_escape", new HtmlEscape());
    freeMarkerConfigurer.setFreemarkerVariables(variables);
    return freeMarkerConfigurer;
}

如果是xml中配置,其配置为:

    
   encoding  
   UTF-8  
 
 
   
   forceEncoding  
   true  
 
 

你可能感兴趣的:(JAVA)