@Configurationpublic class FreeMarkerViewResolverConfig { @Bean(name = "viewResolver") public ViewResolver getViewResolver() { FreeMarkerViewResolver viewResolver = new FreeMarkerViewResolver(); viewResolver.setCache(true); viewResolver.setPrefix("/freemarker/"); viewResolver.setSuffix(".ftl"); viewResolver.setOrder(1); viewResolver.setContentType("text/html;charset=UTF-8");//我是因为这一条没有配置,导致乱码 return viewResolver; } @Bean(name = "freemarkerConfig") public FreeMarkerConfigurer getFreemarkerConfig() { FreeMarkerConfigurer config = new FreeMarkerConfigurer(); Properties properties = new Properties(); properties.put("default_encoding", GlobalSetting.WEB_ENCODING); properties.put("output_encoding", GlobalSetting.WEB_ENCODING); properties.put("url_escaping_charset", GlobalSetting.WEB_ENCODING); properties.put("locale","zh_CN"); properties.put("defaultEncoding", GlobalSetting.WEB_ENCODING); properties.put("date_format","yyyy-MM-dd"); properties.put("time_format","HH:mm:ss"); properties.put("datetime_format","yyyy-MM-dd HH:mm:ss"); properties.put("classic_compatible","true"); properties.put("template_exception_handler","rethrow");//#ignore,debug,html_debug,rethrow config.setFreemarkerSettings(properties);// Folder containing FreeMarker templates.// 1 - "/WEB-INF/views/"// 2 - "classpath:/templates" config.setDefaultEncoding(GlobalSetting.WEB_ENCODING); config.setTemplateLoaderPath("classpath:/templates"); return config; }}