---
title: "Spring集成FreeMarker中文出现乱码的解决办法（非contentType）"
author: "allenwei"
date: "2008-07-27T13:32:24Z"
tags: []
categories: ["企业架构"]
slug: "spring-freemarker-contenttype"
draft: false
lastmod: "2008-07-27T13:32:24Z"
id: 220089
url: "https://allenwei.iteye.com/blog/220089"
---

项目中用到freemarker和spring集成后中文出现乱码

上网搜大部分是说在viewResolver中加入&lt;property name="contentType" value="text/html;charset=gb2312"&gt;&lt;/property&gt;

 

但我发现对于我的项目不起做用

 

又goole一下 剔除掉上面的搜索结果，发现还有一种解决方案

&lt;bean id="freemarkerConfigurer"  
        class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"&gt;  
        &lt;property name="templateLoaderPath"&gt;  
            &lt;value&gt;/WEB-INF/freemarker/&lt;/value&gt;  
        &lt;/property&gt;  
        &lt;property name="freemarkerSettings"&gt;  
            &lt;props&gt;  
                &lt;prop key="template\_update\_delay"&gt;1&lt;/prop&gt;  
                &lt;prop key="defaultEncoding"&gt;UTF-8&lt;/prop&gt; &lt;!-- 乱码 重点在这里 也可以改成gb2312--&gt;  
            &lt;/props&gt;  
        &lt;/property&gt;  
    &lt;/bean&gt;

 

这下乱码问题解决了

 

ps：现在信息都是copy&paste，造成信息泛滥，搜到的信息大部分都一模一样，可悲啊！！