FreeMarker中文乱码

共有三处地方需要注意:

FreeMarkerConfigurer

<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
        <property name="templateLoaderPath" value="/WEB-INF/views"/>        
        <property name="freemarkerSettings"> 
        <props>
        
                <prop key="default_encoding">UTF-8prop>
                <prop key="locale">UTF-8prop>
                <prop key="url_escaping_charset">UTF-8prop>
                      
                <prop key="datetime_format">yyyy-MM-dd HH:mm:ssprop>
                <prop key="time_format">HH:mm:ssprop>
                <prop key="number_format">0.####prop>
                <prop key="boolean_format">true,falseprop>
                <prop key="whitespace_stripping">trueprop>
                <prop key="tag_syntax">auto_detectprop>
        props>
        property> 
        <property name="templateLoaderPath">
            <value>WEB-INF/FTL/value>
        property>
    bean>

FreeMarkerViewResolver

<bean id="freemarkerResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
        
        <property name="contentType" value="text/html;charset=UTF-8"/>

          
        <property name="cache" value="true" />
        <property name="prefix" value="" />
        <property name="suffix" value=".ftl" />
        <property name="requestContextAttribute" value="request" />
        <property name="exposeSpringMacroHelpers" value="true" />
        <property name="exposeRequestAttributes" value="true" />
        <property name="exposeSessionAttributes" value="true" />
    bean>

ftl文件编码


<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title heretitle>
head>
<body>
hello你好${name}
body>
html>

注意这一句话:

你可能感兴趣的:(FreeMarker中文乱码)