thymeleaf中文乱码问题

在web.xml加了过滤器也是无法解决的

<filter>
    <filter-name>CharacterEncodingFilterfilter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
    <init-param>
        <param-name>encodingparam-name>
        <param-value>UTF-8param-value>
    init-param>
    <init-param>
        <param-name>forceEncodingparam-name>
        <param-value>trueparam-value>
    init-param>
filter>

<filter-mapping>
    <filter-name>CharacterEncodingFilterfilter-name>
    <url-pattern>/*url-pattern>
    <dispatcher>REQUESTdispatcher>
    <dispatcher>FORWARDdispatcher>
filter-mapping>


需要在spring的配置文件中加入thymeleaf 视图解析器的编码,如:

<bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
    <property name="prefix" value="/WEB-INF/views/templates/" />
    <property name="templateMode" value="HTML5"/>
 
  
   <property name="characterEncoding" value="UTF-8"/>
bean >

<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">    
<property name="templateResolver" ref="templateResolver" />
bean>

<bean  class="org.thymeleaf.spring4.view.ThymeleafViewResolver">  
  <property name="templateEngine" ref="templateEngine" /> 
   <property name="order" value="1" />   
 <property name="viewNames" value="*.html,*.xhtml" /> 
   <property name="characterEncoding" value="UTF-8"/>
bean>


你可能感兴趣的:(thymeleaf)