freemarker 模板填充亂碼

  在本地測試的時候是正常的,但是到了服務器的時候就亂碼了。 web

  查詢了一圈,最後找到此辦法. spring

   Configuration cfg = new Configuration();
   cfg.setEncoding(Locale.CHINA , "UTF-8"); 服務器

   僅此標紅的一句代碼解決了亂碼。 測試

   其實你也能夠在配置文件裏改. 編碼

  好比說: spa

<bean id="freemakerCongfig"
    class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
       <property name="templateLoaderPath">
           <value>/WEB-INF/web/</value>
       </property>
       <property name="freemarkerSettings">
       <props>
       <prop key="defaultEncoding">UTF-8</prop>
       </props>
       </property>
    </bean>

   或者修改配置文件freemarker.properties修改默認編碼。 code

相關文章
相關標籤/搜索